散分:如何在form上显示一个excel表格 本来随便用一个表格控件就可以了,客户刁难,要求表格好看,要有线形颜色,还用excel做了一个模板给我看。我想如果能在form上放置一个excel的表格的话,也就搞定了。到底如何放?怎么操作?请高手不吝赐教. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 非常感谢,确实可以。能操作cell单元吗?象使用vba得方法一样。 贴点操作代码吧。这分全是你的了。比如,如何在指定的cell输入(用程序)。或者得到sheet对象也可以。得到sheet对象应该就可以随心所欲的操作sheet了。 参考参考吧。 一个操作Excel的例程 可以自己看看效果:procedure TForm1.updatexls;varxlapp, sheet : variant;row, i : integer;filename, fh : string;begintryxlapp := createoleobject('excel.application');exceptshowmessage('not found excel in your system, so can not create file!');exit;end;xlapp.visible := true;xlApp.ScreenUpdating := False;tryfor i := 0 to 10 dobeginfh := '';filename := 'E: + Inttostr(i) + '.xls';xlapp.workbooks.add;// xlapp.workbooks[1].saveas(newfilename);sheet := xlapp.workbooks[1].worksheets[1];sheet.pagesetup.LeftMargin := xlapp.InchesToPoints(0);sheet.pagesetup.rightMargin := xlapp.InchesToPoints(0);sheet.pagesetup.topMargin := xlapp.InchesToPoints(0);sheet.pagesetup.bottomMargin := xlapp.InchesToPoints(0);sheet.pagesetup.headerMargin := xlapp.InchesToPoints(0);sheet.pagesetup.footerMargin := xlapp.InchesToPoints(0);fh := VarAsType(sheet.cells[1, 6], varstring);xlapp.Range[sheet.cells[1, 1], sheet.cells[9, 82]].MergeCells := False; //?? 3y o? 2¢xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[1, 1], sheet.cells[13, 82]].select;xlapp.selection.ShrinkToFit := False; //×? ?ˉ ì? 3?xlapp.selection.AddIndent := False; //?? ?ó ?? ??xlapp.selection.WrapText := False; //×? ?ˉ ?? DDxlapp.selection.ClearContents; //?? 3y ?ú èYxlapp.selection.borders[5].LineStyle := xlnone;xlapp.selection.borders[6].LineStyle := xlnone;xlapp.selection.Orientation := 0;xlapp.selection.font.name := '?? ì? ';xlapp.selection.font.size := '10';xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.NumberFormatLocal := 'G/í¨ ó? ?? ê? ';sheet.cells[1, 1] := '?? o? :';xlapp.range[sheet.cells[1, 1], sheet.cells[1, 1]].font.Name := '?? ì? _GB2312';xlapp.range[sheet.cells[1, 1], sheet.cells[1, 1]].font.size := 18;xlapp.range[sheet.cells[1, 1], sheet.cells[1, 1]].font.Bold := true;xlapp.Range[sheet.cells[1, 1], sheet.cells[1, 5]].MergeCells := true;sheet.cells[1, 6] := fh;xlapp.range[sheet.cells[1, 6], sheet.cells[1, 6]].font.Name := 'Times New Roman';xlapp.range[sheet.cells[1, 6], sheet.cells[1, 6]].font.size := 18;xlapp.Range[sheet.cells[1, 6], sheet.cells[1, 30]].MergeCells := true;sheet.cells[3, 1] := '?- ?? ';xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 31]].select;xlapp.Range[sheet.cells[3, 1], sheet.cells[10, 5]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;xlapp.selection.Orientation := xlVertical;for row := 3 to 10 do //?- ?? ?- á?beginxlapp.Range[sheet.cells[row, 6], sheet.cells[row, 7]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.VerticalAlignment := xlcenter;xlapp.Range[sheet.cells[row, 8], sheet.cells[row, 25]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.VerticalAlignment := xlcenter;xlapp.Range[sheet.cells[row, 26], sheet.cells[row, 30]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;end;sheet.cells[3, 31] := '?ú à- ?a ?è :';for row := 1 to 3 dobeginxlapp.Range[sheet.cells[row * 2 + 1, 31], sheet.cells[row * 2 + 2, 35]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;xlapp.Range[sheet.cells[row * 2 + 1, 36], sheet.cells[row * 2 + 2, 43]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;end;for row := 12 to 13 dobeginxlapp.Range[sheet.cells[row, 73], sheet.cells[row, 82]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;end;row := 11;xlapp.Range[sheet.cells[row, 31], sheet.cells[row + 2, 66]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.VerticalAlignment := xltop;sheet.rows.item['1'].RowHeight := 22;xlapp.Range[sheet.cells[2, 1], sheet.cells[13, 82]].select;xlapp.selection.borders[7].LineStyle := 1;xlapp.range[sheet.cells[16, 1], sheet.cells[16, 1]].select;xlapp.displayalerts := false;sheet.saveas(FileName);xlapp.workbooks[1].close;VarClear(Sheet);end;xlapp.quit;Application.ProcessMessages;finallyxlapp.ScreenUpdating := True;end;end; 谢谢,这是vba,我也会。关键是如何用vba操作olecontainer中的sheet。 delphi 动态连接库调用exe中的函数,时出现access violation at 0x0047a214 :read of address 0x0047 对消息及窗口函数的理解 制作安装程序求助! 程序模块化设计开发方法...up有分 放分别问理由之一 关于Delphi自带例子中一个看不懂的地方 谁来捡分? 薪资软件自定义工资项目,公式 Database控件越多,是否速度越快呢? 请大虾指点:类型库的数据类型问题?一定加分!!! TabOrder的问题 关于FindWindow函数 在线等
比如,如何在指定的cell输入(用程序)。或者得到sheet对象也可以。得到sheet对象应该就可以随心所欲的操作sheet了。
可以自己看看效果:procedure TForm1.updatexls;varxlapp, sheet : variant;row, i : integer;filename, fh : string;begintryxlapp := createoleobject('excel.application');exceptshowmessage('not found excel in your system, so can not create file!');exit;end;xlapp.visible := true;xlApp.ScreenUpdating := False;tryfor i := 0 to 10 dobeginfh := '';filename := 'E: + Inttostr(i) + '.xls';xlapp.workbooks.add;// xlapp.workbooks[1].saveas(newfilename);sheet := xlapp.workbooks[1].worksheets[1];sheet.pagesetup.LeftMargin := xlapp.InchesToPoints(0);sheet.pagesetup.rightMargin := xlapp.InchesToPoints(0);sheet.pagesetup.topMargin := xlapp.InchesToPoints(0);sheet.pagesetup.bottomMargin := xlapp.InchesToPoints(0);sheet.pagesetup.headerMargin := xlapp.InchesToPoints(0);sheet.pagesetup.footerMargin := xlapp.InchesToPoints(0);fh := VarAsType(sheet.cells[1, 6], varstring);xlapp.Range[sheet.cells[1, 1], sheet.cells[9, 82]].MergeCells := False; //?? 3y o? 2¢xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 1]].entirerow.insert;xlapp.Range[sheet.cells[1, 1], sheet.cells[13, 82]].select;xlapp.selection.ShrinkToFit := False; //×? ?ˉ ì? 3?xlapp.selection.AddIndent := False; //?? ?ó ?? ??xlapp.selection.WrapText := False; //×? ?ˉ ?? DDxlapp.selection.ClearContents; //?? 3y ?ú èYxlapp.selection.borders[5].LineStyle := xlnone;xlapp.selection.borders[6].LineStyle := xlnone;xlapp.selection.Orientation := 0;xlapp.selection.font.name := '?? ì? ';xlapp.selection.font.size := '10';xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.NumberFormatLocal := 'G/í¨ ó? ?? ê? ';sheet.cells[1, 1] := '?? o? :';xlapp.range[sheet.cells[1, 1], sheet.cells[1, 1]].font.Name := '?? ì? _GB2312';xlapp.range[sheet.cells[1, 1], sheet.cells[1, 1]].font.size := 18;xlapp.range[sheet.cells[1, 1], sheet.cells[1, 1]].font.Bold := true;xlapp.Range[sheet.cells[1, 1], sheet.cells[1, 5]].MergeCells := true;sheet.cells[1, 6] := fh;xlapp.range[sheet.cells[1, 6], sheet.cells[1, 6]].font.Name := 'Times New Roman';xlapp.range[sheet.cells[1, 6], sheet.cells[1, 6]].font.size := 18;xlapp.Range[sheet.cells[1, 6], sheet.cells[1, 30]].MergeCells := true;sheet.cells[3, 1] := '?- ?? ';xlapp.Range[sheet.cells[3, 1], sheet.cells[3, 31]].select;xlapp.Range[sheet.cells[3, 1], sheet.cells[10, 5]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;xlapp.selection.Orientation := xlVertical;for row := 3 to 10 do //?- ?? ?- á?beginxlapp.Range[sheet.cells[row, 6], sheet.cells[row, 7]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.VerticalAlignment := xlcenter;xlapp.Range[sheet.cells[row, 8], sheet.cells[row, 25]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.VerticalAlignment := xlcenter;xlapp.Range[sheet.cells[row, 26], sheet.cells[row, 30]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;end;sheet.cells[3, 31] := '?ú à- ?a ?è :';for row := 1 to 3 dobeginxlapp.Range[sheet.cells[row * 2 + 1, 31], sheet.cells[row * 2 + 2, 35]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;xlapp.Range[sheet.cells[row * 2 + 1, 36], sheet.cells[row * 2 + 2, 43]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;end;for row := 12 to 13 dobeginxlapp.Range[sheet.cells[row, 73], sheet.cells[row, 82]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlcenter;xlapp.selection.VerticalAlignment := xlcenter;end;row := 11;xlapp.Range[sheet.cells[row, 31], sheet.cells[row + 2, 66]].select;xlapp.selection.MergeCells := true;xlapp.selection.HorizontalAlignment := xlgeneral;xlapp.selection.VerticalAlignment := xltop;sheet.rows.item['1'].RowHeight := 22;xlapp.Range[sheet.cells[2, 1], sheet.cells[13, 82]].select;xlapp.selection.borders[7].LineStyle := 1;xlapp.range[sheet.cells[16, 1], sheet.cells[16, 1]].select;xlapp.displayalerts := false;sheet.saveas(FileName);xlapp.workbooks[1].close;VarClear(Sheet);end;xlapp.quit;Application.ProcessMessages;finallyxlapp.ScreenUpdating := True;end;end;