Excel报表输出-讲稿.ppt

上传人:本田雅阁 文档编号:3480844 上传时间:2019-09-01 格式:PPT 页数:23 大小:2.96MB
返回 下载 相关 举报
Excel报表输出-讲稿.ppt_第1页
第1页 / 共23页
Excel报表输出-讲稿.ppt_第2页
第2页 / 共23页
Excel报表输出-讲稿.ppt_第3页
第3页 / 共23页
Excel报表输出-讲稿.ppt_第4页
第4页 / 共23页
Excel报表输出-讲稿.ppt_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《Excel报表输出-讲稿.ppt》由会员分享,可在线阅读,更多相关《Excel报表输出-讲稿.ppt(23页珍藏版)》请在三一文库上搜索。

1、Excel报表输出,林渊钟,2019/9/1,Excel对象模型 对象基本操作 Application对象 Workbooks对象 Worksheets对象 Range对象 Excel操作方法扩展(VBA宏) 性能优化 FastExport Singleton 套用模板输出Excel 动态输出设计,内容提要,1.Excel对象模型,创建 释放,2.1Application对象,打开 关闭,2.2Workbooks对象,设置当前操作的sheet,2.3Worksheets对象,获取Range : 单个: (Range)_workSheet.Cellstop, left; 区域: _workShe

2、et.get_Range(“B3:D5”, Type.Missing); _workSheet.get_Range(_workSheet.Cells3, 2,_workSheet.Cells5, 4); 合并单元格: if(range.Count 1) range.Merge(Missing.Value); 设置单元格值: range.NumberFormatLocal = “”; /文本格式,“.0_”一位小数 range.Value2 = value; /区别range.Value,2.4Range对象,格式化目标单元格: styleRange.Copy(Missing.Value); o

3、bjectRange.PasteSpecial(XlPasteType.xlPasteFormats, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false); 序列填充: startRange.Value2 = “1”; /填充第一个单元格序号1 startRange.AutoFill(destination, XlAutoFillType.xlFillSeries); 设置公式: targetRange.Formula = “=SUM(B3:B10)”; targetRange.FormulaR1C1=“=SUM

4、(R-3C-2:R-1C-2,R-3C:R-1C)”;,Range对象,3.Excel操作方法扩展,工具-宏-录制新宏,工具-宏-Visual Basic 编辑器,报表输出基本流程,4.1 性能优化 FastExport,Cell by Cell,Fast Export,Demo,public void FastExportToExcel(System.Data.DataTable dt, int startTop, int startLeft) / Copy the DataTable to an object array object, rawData = new objectdt.Row

5、s.Count, dt.Columns.Count; / Copy the values to the object array for (int row = 0; row dt. Rows.Count; col+) for (int col = 0; col dt. Columns.Count; row+) rawDatarow, col = value; Range range = GetRange(startTop, startLeft, dt.Rows.Count, dt.Columns.Count); / Fast data export to Excel range.Value2

6、= rawData; ,FastExport,创建二维数组,二维数组赋值,直接填值,转置处理?,4.2 性能优化2单例模式,耗费大量的内存和时间,耗费大量的内存和时间,单例模式,public class ExcelOperator private static ExcelOperator instance; private ApplicationClass _appClass = null; private _Workbook _workBook = null; private string _filePath = “; public string FileName get return _f

7、ilePath; private ExcelOperator(string filePath) _appClass = new ApplicationClass(); _appClass.Visible = false; Open(filePath); /打开workbook 赋值_filePath = filePath public static ExcelOperator GetInstance(string filePath) if (instance = null) instance = new ExcelOperator(filePath); /保证仅实例化一次 return ins

8、tance; ,5.套用模板输出Excel,1)固定单元格填充(CellInfo类) 2)动态生成表头(仅动态Excel表) 3)从数据库获取DataTable,快速填充,CelleInfo类构造函数: CellInfo(string content, int top, int left) CellInfo(string content, int top, int left, int finalTop, int finalLeft) 例:如果要合并B3-D5共9个单元格,并填写“内容”两个字,则使用CellInfo(“内容”,3,2,5,4),6.动态输出设计,1.统计 /删除现有统计表 Dr

9、opTable(DataAccess GisDbAccess, string tableName); / 根据字段lstItemInfo列表生成统计表tableName CreateTable(DataAccess GisDbAccess, string tableName, List lstItemInfo); /删除统计的存储过程 DropProcedure(DataAccess GisDbAccess, string procName); /创建统计的存储过程 string procString = GetGenerateStatProcSQL(); /存储过程的SQL语句 Create

10、StatProcedure(DataAccess GisDbAccess, string procString); /执行统计的存储过程 RunProcedure(string storedProcName, IDataParameter parameters); 2.获取数据 /删除获取统计表数据的存储过程 DropProcedure(DataAccess GisDbAccess, string procName); /创建获取统计表数据的存储过程 string SQLString = GetGenerateSelectProcSQL(); /存储过程的SQL语句 ExecuteSql(string SQLString); /执行获取统计表数据的存储过程 DataSet RunProcedure(string storedProcName, IDataParameter parameters, string tableName);,补充:Excel限制,Crystal Report 优点:编程实现简单;可集成到界面中显示;支持脚本语言;自动分页 缺点:不能由用户定制报表格式;表头不能动态生成 Excel 优点:页面布局设计灵活;代码操作数据更灵活精确 缺点:行列数有限制,与其它报表比较-水晶报表,Thank You !,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1