Blog信息 |
blog名称:注册会计师(注会)练习软件 日志总数:398 评论数量:116 留言数量:27 访问次数:3274464 建立时间:2005年6月6日 |

| |
[delpih编程]让ejungrid导出excel时也保存公式 软件技术
吕向阳 发表于 2010/8/13 13:55:21 |
ejungrid处理导入excel基本无损失,但在保存时,只能保存数值,不能保存公式。但这丝毫不影响作为一个插件的优秀之处,因为它的界面与excel配合的太出色了。经过一番研究,发现xlsreadwriteII这个插件可以弥补这个小缺撼。思路是在ejungrid调出表格后,要保存时,不调用savetoexcel事件,此时调用xlsreadwriteII插件,读取源文件,比较两个控件每个单元格的字符串是否相同,相同不处理,不相同将改动保存到xlsreadwrite的单元格上,最后xlsreadwriteII的单元格就是我们想要保存的结果了,再调用xlsreadwriteii的write功能就完工了。说了这么多,其实代码比较短。procedure TForm1.btn5Click(Sender: TObject);var i, j: integer; aformula: string;begin xls_1.Filename := 'd:\a000.xls'; xls_1.Read; for i := 0 to xls_1.Sheets[0].lastrow do for j := 0 to xls_1.Sheets[0].lastcol do begin mmo1.lines.add(xls_1.Sheets[0].AsString[j, i]); mmo1.Lines.Add(ejungrid1.Cells[j + 1, i + 1].Text); if Trim(xls_1.Sheets[0].AsString[j, i]) <> Trim(ejungrid1.Cells[j + 1, i + 1].Text) then begin aformula := ejungrid1.Cells[j + 1, i + 1].Formula; if aformula <> '' then xls_1.Sheets[0].AsFormula[j, i] := aformula else xls_1.Sheets[0].AsString[j, i] := Trim(ejungrid1.Cells[j + 1, i + 1].Text); end; end; xls_1.Filename := 'd:\a001.xls'; xls_1.Write;end;有了这个,基本上ejungrid就是我随心控制excel的宝刀了。 |
|
|