5,388
社区成员
发帖
与我相关
我的任务
分享
try
Excel.ActiveSheet.Rows[3].Delete;
Excel.ActiveSheet.Columns[5].Delete;
Excel.ActiveSheet.Columns[6].Delete;
Excel.Cells[1,1].Value := 'CARRIER';
Excel.Cells[1,2].Value := 'CI';
Excel.Cells[1,5].Value := 'changeType';
Excel.Cells[1,6].Value := 'success';
WorkBook.Worksheets[1].Name := 'Sheet1';
Excel.DisplayAlerts := true;
finally
Excel.Quit;
Excel := Unassigned;
end;
我打开一个EXCEL对它进行上面的操作然后退出EXCEL它提示是否对所做的修改进行保存,这时我手动的选择保存为97-2003工作薄。
这种做法没有任何问题!
但是我用
excel.WorkBooks[1].SaveAs('c:\Sheet1.xls');
保存得来的文件,打开时会提示你尝试打开的文件XX的格式与文件扩展名指定的格式不一致。
这个问题怎么解决?
我找个网上的两种方法都不行,一中是修改注册表里弄DefaultFormat的值为0x38(56),还有一种是saveas函数的一个参数指定保存格式也不行。那个参数有好多EXCEL的格式。看不懂
XlFileFormat
Constant Value
xlExcel2 16
xlExcel2FarEast 27
xlExcel3 29
xlExcel4 33
xlExcel4Workbook 35
xlExcel5 39
我的EXCEL是2007版。2003版也试了还是不行。
xlAddIn Microsoft Office Excel Add-In.
xlCSV Comma separated value.
xlCSVMac Comma separated value.
xlCSVMSDOS Comma separated value.
xlCSVWindows Comma separated value.
xlCurrentPlatformText Specifies a type of text format
xlDBF2 Dbase 2 format.
xlDBF3 Dbase 3 format.
xlDBF4 Dbase 4 format.
xlDIF Data Interchange format.
xlExcel2 Excel version 2.0.
xlExcel2FarEast Excel version 2.0 far east.
xlExcel3 Excel version 3.0.
xlExcel4 Excel version 4.0.
xlExcel4Workbook Excel version 4.0. Workbook format.
xlExcel5 Excel version 5.0.
xlExcel7 Excel 95.
xlExcel9795 Excel version 95 and 97.
xlHtml Web page format.
xlIntlAddIn Microsoft Office Excel Add-In international format.
xlIntlMacro Deprecated format.
xlSYLK Symbolic link format.
xlTemplate Excel template format.
xlTextMac Specifies a type of text format.
xlTextMSDOS Specifies a type of text format.
xlTextPrinter Specifies a type of text format.
xlTextWindows Specifies a type of text format.
xlUnicodeText Specifies a type of text format.
xlWebArchive MHT format.
xlWJ2WD1 Deprecated format.
xlWJ3 Deprecated format.
xlWJ3FJ3 Deprecated format.
xlWK1 Lotus 1-2-3 format.
xlWK1ALL Lotus 1-2-3 format.
xlWK1FMT Lotus 1-2-3 format.
xlWK3 Lotus 1-2-3 format.
xlWK3FM3 Lotus 1-2-3 format.
xlWK4 Lotus 1-2-3 format.
xlWKS Lotus 1-2-3 format.
xlWorkbookNormal Excel workbook format.
xlWorks2FarEast Microsoft Works 2.0 format
xlWQ1 Quattro Pro format.
xlXMLSpreadsheet Excel Spreadsheet format.
unit u_formatXls;
interface
uses
Variants, ComObj;
//格式化小区切换表xls
function formatChange(fileName:string):Boolean;
implementation
function formatChange(fileName:string):Boolean;
var
Excel,WorkBook: OleVariant;
Sheet: Variant;
i:integer;
begin
try
excel := CreateOleObject('Excel.Application');
WorkBook := excel.Workbooks.Add(fileName);
Sheet := WorkBook.Worksheets[1];
except
result := false ;
EXIT;
end;
try
//excel.Visible:=true; //显示EXCEL
Excel.ActiveSheet.Rows[3].Delete;
Excel.ActiveSheet.Rows[2].Delete;
Excel.ActiveSheet.Rows[1].Delete;
Excel.ActiveSheet.Columns[21].Delete;
Excel.ActiveSheet.Columns[20].Delete;
Excel.ActiveSheet.Columns[19].Delete;
Excel.ActiveSheet.Columns[1].Delete;
Excel.ActiveSheet.Columns[1].Delete;
Excel.ActiveSheet.Columns[1].Delete;
Excel.ActiveSheet.Columns[1].Delete;
Excel.ActiveSheet.Columns[1].Delete;
Excel.ActiveSheet.Columns[1].Delete;
Excel.ActiveSheet.Columns[3].Delete;
Excel.ActiveSheet.Columns[5].Delete;
Excel.ActiveSheet.Columns[6].Delete;
Excel.Cells[1,1].Value := 'CARRIER';
Excel.Cells[1,2].Value := 'CI';
Excel.Cells[1,3].Value := 'NCARRIER';
Excel.Cells[1,4].Value := 'NCI';
Excel.Cells[1,5].Value := 'changeType';
Excel.Cells[1,6].Value := 'success';
Excel.Cells[1,7].Value := 'invalidPilotFail';
Excel.Cells[1,8].Value := 'blockFail';
Excel.Cells[1,9].Value := 'otherFail';
WorkBook.Worksheets[1].Name := 'Sheet1';
excel.WorkBooks[1].SaveAs('c:\Sheet1.xls',excel.XlFileFormat.xlExcel5);
finally
Excel.Quit;
Excel := Unassigned;
end;
result := true ;
end;
end.