当然支持,只是你写错了。应该是:CreateOleObject(Excel.Application)" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > win7 + <em>delphi</em> 7 + <em>excel2007&l

win7 + <em>delphi</em> 7 + <em>excel2007&l

作者:乔山办公网日期:

返回目录:excel表格制作




当然支持,只是你写错了。应该是:
CreateOleObject('Excel.Application');
拿Excel 2010做例子:
首先,需要在最上面的e79fa5e98193e4b893e5b19e362uses 里面 加上comObj

//AXLSFile 表示文件路径
procedure Xls_To_StringGrid(AXLSFile: string);
const
xlCellTypeLastCell = $0000000B;
var
XLApp, Sheet: OLEVariant;
RangeMatrix: Variant;
x, y, k, r: Integer;
vLen : integer;
begin
XLApp := CreateOleObject('Excel.Application');
try
// Hide Excel
XLApp.Visible := False;
// Open the Workbook
XLApp.Workbooks.Open(AXLSFile);

Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];

// In order to know the dimension of the WorkSheet, i.e the number of rows
// and the number of columns, we activate the last non-empty cell of it

Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
// Get the value of the last row
x := XLApp.ActiveCell.Row;
// Get the value of the last column
y := XLApp.ActiveCell.Column;

// Assign the Variant associated with the WorkSheet to the Delphi Variant

RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
// Define the loop for filling in the TMOStringGrid

//假设是导入到表格中, 2开头表示忽略第一行表头
for k := 2 to x do
begin
eGrid.Cells[1, k - 1] := RangeMatrix[k, 1]; //Excel中第一行第一列都是从1 开始
end;
// Unassign the Delphi Variant Matrix
RangeMatrix := Unassigned;
finally
// Quit Excel
if not VarIsEmpty(XLApp) then
begin
// XLApp.DisplayAlerts := False;
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
end;
end;
end;

如果不支持,那就只能使用控件的办法,如zhidao果想使用excel2007,这个delphi7自带的控件是不支持的,解决办法有二:

1. 自己导入excel2007的动态库。

2. 使用第三方控件,比如NativeExcel。

顺便提一句: 貌似COM方式应该是兼容性最好的吧,怎么不支持呢?

相关阅读

  • <em>Delphi</em>中如何将<em>excel</em>中的数

  • 乔山办公网excel表格制作
  • a和b的字段类型是不是有Double类型?请检查Excel中是不是出现了除数字外的其他字符所以导致你插入数据库时会出现错误提示(string类型不能转换成double类型)delphi中怎么实现EXCEL导入导出到
  • <em>delphi</em> 如何写入<em>Excel</em>-d

  • 乔山办公网excel表格制作
  • Delphi中对Excel的操作:ExcelApplicat..." src="/uploads/tu/63.jpg" style="width: 400px; height: 267px;" />在开发数据库应用程序中,经常要将类型相同的数据导出来,放到Excel文件中,利用Excel强大的编辑功
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网