标题: use TestComplete :chang Excel to CSV [打印本页] 作者: shanshan3301 时间: 2013-4-3 23:31 标题: use TestComplete :chang Excel to CSV 在这里介绍了一下怎么把.xlsx 转成.csv文件
/* 4.3.2013
shanshan xu
XLSX2CSV*/
function Xls2Csv()
{
var Excel = Sys.OleObject("Excel.Application");
Excel.Workbooks.Open("C:\\Planar_UI_ComponentIDs.xlsx");//The Excel file path
var fso = new ActiveXObject("Scripting.FileSystemObject");
var cntSheets = Excel.ActiveWorkbook.Sheets.count;
for ( si = 1; si <= cntSheets; si++)//read every sheet
{
var sheetname = Excel.ActiveWorkbook.Sheets(si).name;//get the name from sheet
var fname="C:\\res\\"+sheetname+".csv";//the target folder to Storing files
var f1 = fso.createtextfile(fname);//create the same name for every sheet
var RowCount = Excel.ActiveWorkbook.Sheets(si).usedRange.Rows.Count;
var ColumnCount = Excel.ActiveWorkbook.Sheets(si).usedRange.Columns.Count;
for (var i = 1; i <= RowCount; i++)
{
var s = "";
for (var j = 1; j <= ColumnCount; j++)
{
s=VarToString(Excel.ActiveWorkbook.sheets(si).Cells(i, j));
if (j != ColumnCount)
{
f1.Write("\""+s+"\"");
f1.Write(",")
}
else
{
f1.WriteLine("\""+s+"\"");
}
}
}
f1.close();
}
//f1.close();
Excel.Quit();
}作者: happyrichman 时间: 2015-7-1 10:26
ding