您好!
您的意思是想导出的Excel文件可以用Excel2003打开是吧!在默认情况下我们导出的Excel是.xlsx 的格式。如果想要兼容低版本的office就需要导出保存的时候保存为 .xls 的格式H5下的代码设置如下:
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>XLSX Export</title>
- <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
- <link rel="stylesheet" type="text/css" href="css/GrapeCity.ActiveReports.Viewer.Html.css" />
- <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
- <script src="js/GrapeCity.ActiveReports.Viewer.Html.js"></script>
- <script type="text/javascript">
- var reportName = 'Reports/Symbol.rdlx';
- var viewer;
- // init viewer
- $(function () {
- viewer = GrapeCity.ActiveReports.Viewer({
- element: '#viewer',
- uiType: 'desktop',
- reportService: { url: '/ActiveReports.ReportService.asmx' },
- report: { id: reportName },
- <font color="#ff0000"> availableExports: ['Xls']</font>
- });
- $(window).bind('beforeunload', function () {
- viewer.destroy();
- });
- });
- var customExport = function () {
- <font color="#ff0000"> viewer.export("Xls", function (uri) { window.open(uri); }, true, { FileName: "MyFileName" });</font>
- // viewer.export("Pdf", function (uri) { window.open(uri); }, true, { FileName: "MyFileName" });
- };
- // replace export button
- $(document).ready(function () {
- ////pdfDocument: "PDF Document",
- //wordDocument: "Word Document",
- //imageFile: "Image File",
- //mhtDocument: "MHTML Web Archives",
- //excelWorkbook: "Excel Workbook",
- var list = ["Word Document", "Excel Workbook"];
- for (var i = 0; i < list.length; i++) {
- var excelLink = $('a:contains("' + list[i] + '")');
- ko.cleanNode(excelLink[0]);
- excelLink.removeAttr('data-bind');
- excelLink.removeAttr('disabled');
- excelLink.attr('target', '_blank');
- excelLink.attr('href', 'javascript:customExport()');
- }
-
- });
- </script>
- </head>
- <body>
- <div id="viewer" style="width: 100%; height: 600pt;"></div>
- </body>
- </html>
复制代码 在winfrom的平台下这样设置:
- private void tsbExcel_Click(object sender, EventArgs e)
- {
- string file_name = @"..\..\RdlReport1.rdlx";
- //GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(@"123.rdlx"));
- //GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
- GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
- pageReport.Document.LocateDataSource += new LocateDataSourceEventHandler(LocateData);
- this._document = pageReport.Document;
-
- System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyExcel");
- outputDirectory.Create();
-
- GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
- <font color="#ff0000"> excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;</font>
- excelSetting.MultiSheet = false;
- GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;
- GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
- GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
- outputProvider.OverwriteOutputFile = false;
- _document.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());
- }
复制代码
|