找回密码
 立即注册

QQ登录

只需一步,快速开始

anetmouse

注册会员

1

主题

2

帖子

7

积分

注册会员

积分
7
最新发帖

[已处理] pdf转word

anetmouse
注册会员   /  发表于:2019-3-19 13:57  /   查看:3142  /  回复:3
你好管理员

我现在用ActiveReports生成pdf报表。
现在想直接用Word或者Excel格式的,
所以想问问有没有可能在现有的模板基础上,
直接生成Word或者Excel文档。
求Sample代码。



3 个回复

倒序浏览
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2019-3-19 14:02:37
沙发
您好,如下是导出Word和导出Excel的代码:
导出Word
  1. // Provide the page report you want to render.
  2. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
  3. GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

  4. // Create an output directory.
  5. System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyWord");
  6. outputDirectory.Create();

  7. // Provide settings for your rendering output.
  8. GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new GrapeCity.ActiveReports.Export.Word.Page.Settings();

  9. // Set the FileFormat property to .OOXML.
  10. wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML;

  11. // Set the rendering extension and render the report.
  12. GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
  13. GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));

  14. // Overwrite output file if it already exists.
  15. outputProvider.OverwriteOutputFile = true;

  16. reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting);         
复制代码
导出Excel
  1. // Provide the page report you want to render.
  2. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);

  3. // Create an output directory.
  4. System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyExcel");
  5. outputDirectory.Create();

  6. // Provide settings for your rendering output.
  7. GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
  8. excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
  9. GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;

  10. // Set the rendering extension and render the report.
  11. GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
  12. GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));

  13. // Overwrite output file if it already exists.
  14. outputProvider.OverwriteOutputFile = true;

  15. reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
复制代码


回复 使用道具 举报
anetmouse
注册会员   /  发表于:2019-3-19 14:09:53
板凳
谢谢
回复 使用道具 举报
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2019-3-19 17:55:55
地板
不客气
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部