C
citybug_ch
Unregistered / Unconfirmed
GUEST, unregistred user!
按照在大富翁中一个帖子的方法动态生成EXCEL,但是设置列的宽度不能通过编译。程序如下:
procedure TfrmZeroBasicInfo.bPrintClick(Sender: TObject);
var
ExcelApp:Variant;
ExcelWorkBook: Variant;
ExcelWorkSheet:Variant;
X1: olevariant;
begin
try
ExcelApp:=UnAssigned;
ExcelApp:=CreateOleObject('Excel.Application');
except
showmessage('请检查系统是否已经安装了EXCEL');
Exit;
end;
ExcelApp.WorkBooks.Add;
ExcelApp.WorKSheets[1].Activate;
ExcelApp.ActiveSheet.columns[1].ColumnsWidth:=500;
ExcelApp.ActiveSheet.Columns[1].Align:=center;
ExcelApp.ActiveSheet.Range['A1','E1'].Merge(X1);
ExcelApp.ActiveSheet.Rows[1].Font.Size:=14;
ExcelApp.ActiveSheet.Rows[1].Font.Bold:=True;
ExcelApp.Cells[1,1].Value:='社区基本情况';
ExcelApp.Visible:=True;
ExcelApp.ActiveSheet.PrintPreview;
//ExcelWorkBook.close;
ExcelApp.Quit;
//ExcelWorkSheet:=UnAssigned;
//ExcelWorkBook:=UnAssigned;
ExcelApp:=UnAssigned;
end;
请问:如何设置列的宽度和单元格中字符居中?能否设置单元格的格式呢?
procedure TfrmZeroBasicInfo.bPrintClick(Sender: TObject);
var
ExcelApp:Variant;
ExcelWorkBook: Variant;
ExcelWorkSheet:Variant;
X1: olevariant;
begin
try
ExcelApp:=UnAssigned;
ExcelApp:=CreateOleObject('Excel.Application');
except
showmessage('请检查系统是否已经安装了EXCEL');
Exit;
end;
ExcelApp.WorkBooks.Add;
ExcelApp.WorKSheets[1].Activate;
ExcelApp.ActiveSheet.columns[1].ColumnsWidth:=500;
ExcelApp.ActiveSheet.Columns[1].Align:=center;
ExcelApp.ActiveSheet.Range['A1','E1'].Merge(X1);
ExcelApp.ActiveSheet.Rows[1].Font.Size:=14;
ExcelApp.ActiveSheet.Rows[1].Font.Bold:=True;
ExcelApp.Cells[1,1].Value:='社区基本情况';
ExcelApp.Visible:=True;
ExcelApp.ActiveSheet.PrintPreview;
//ExcelWorkBook.close;
ExcelApp.Quit;
//ExcelWorkSheet:=UnAssigned;
//ExcelWorkBook:=UnAssigned;
ExcelApp:=UnAssigned;
end;
请问:如何设置列的宽度和单元格中字符居中?能否设置单元格的格式呢?