[英]Export SQL file into Excel
I have a sql file which has a lot of insert statements (1000+), 我有一个SQL文件,其中包含很多插入语句(1000+),
eg 例如
insert into `pubs_for_client` (`ID`, `num`, `pub_name`, `pub_address`, `pub_tele`, `pub_fax`, `pub_email`, `publ_website`, `publ_vat`, `pub_last_year`, `titles_on_backlist`, `Personnel`) values('2475','2473','xxx xxx xxx','xxx xxx, xxxx, xxxx, xxxx, ','000000 ','0000 ',NULL,NULL,NULL,NULL,NULL,NULL);
My client wants these in an excel file. 我的客户希望将这些保存在excel文件中。
Is it possible to extract the information from this sql file and import it into an excel spreadsheet? 是否可以从此sql文件中提取信息并将其导入到Excel电子表格中? I'm using excel 2007.
我正在使用Excel 2007。
如果您在某处安装了mysql并且安装了phpMyAdmin,则只需导入.sql文件,然后直接从phpMyAdmin中将表导出为.xls文件即可。
edit: If you want to extract the data from the Insert statements without actually running them, you could: 编辑:如果要从Insert语句中提取数据而不实际运行它们,则可以:
If you are not keen on installing any tools you could try this...its simple but needs some regex matching with trial and error for strings. 如果您不希望安装任何工具,可以尝试一下...虽然很简单,但是需要一些正则表达式,并需要反复试验字符串。
Side Note : you could also try asking your client to send it in excel henceforth its usually available in most data providers. 旁注:您也可以尝试要求您的客户以excel格式发送它,此后它通常在大多数数据提供程序中都可用。
You mean export the values? 您是说导出值?
Assuming you're using the SQL server + tools the simplest method would be to 假设您使用的是SQL Server +工具,最简单的方法是
select * from pubs_for_client
You'll have to set the column widths yourself, and if you have number-as-a-string columns you want to keep as strings (eg to preserve leading zeroes) then you'll need to set the receiving column type first. 您必须自己设置列宽,如果您要保留字符串形式的数字列(例如,保留前导零),则需要首先设置接收列的类型。
If not, and if you can't use similar tools for your database, you can use regexps or just use your text editor to convert your SQL file into a CSV which Excel will read. 如果不是这样,并且如果不能在数据库中使用类似的工具,则可以使用正则表达式或仅使用文本编辑器将SQL文件转换为Excel可以读取的CSV。 You'd also have to edit out quotes from values and nulls and doubled-to-quote apostrophes.
您还必须删除值,空值和双引号撇号的引号。 Unfortunately you can't then specify column types in advance and you would eg lose leading zeros on numbers.
不幸的是,您之后不能预先指定列类型,例如,数字会丢失前导零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.