我正在使用PdfReport
库生成报告.pdf
文件。
PdfReport是一个基于Epplus和iTextsharp的库,这就是我们选择这个库的原因 - 因为我们想要生成PDF和EXCEL文件。
目前我们能够生成生成的PDF文件似乎无法生成Excel文件。
Google对这个图书馆的帮助不大。
这是我的代码
public class IListPdfReport
{
public IPdfReportData CreatePdfReport(DataSet mTables)
{
return new PdfReport().DocumentPreferences(doc =>
{
doc.RunDirection(PdfRunDirection.LeftToRight);
doc.Orientation(PageOrientation.Portrait);
doc.PageSize(PdfPageSize.A4);
doc.DocumentMetadata(new DocumentMetadata { Author = "Vahid", Application = "PdfRpt", Keywords = "IList Rpt.", Subject = "Test Rpt", Title = "Test" });
doc.Compression(new CompressionSettings
{
EnableCompression = true,
EnableFullCompression = true
});
doc.PrintingPreferences(new PrintingPreferences
{
ShowPrintDialogAutomatically = true
});
})
.DefaultFonts(fonts =>
{
fonts.Path(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\arial.ttf"),
System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\verdana.ttf"));
fonts.Size(9);
fonts.Color(System.Drawing.Color.Black);
})
.PagesFooter(footer =>
{
footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
})
.MainTableTemplate(template =>
{
template.BasicTemplate(BasicTemplate.AppleOrchardTemplate);
})
.MainTablePreferences(table =>
{
table.ColumnsWidthsType(TableColumnWidthType.FitToContent);
table.NumberOfDataRowsPerPage(10);
})
.MainTableDataSource(dataSource =>
{
dataSource.DataTable(mTables.Tables[2]);
})
.MainTableSummarySettings(summarySettings =>
{
summarySettings.OverallSummarySettings("Summary");
summarySettings.PreviousPageSummarySettings("Previous Page Summary");
summarySettings.PageSummarySettings("Page Summary");
})
.MainTableColumns(columns =>
{
columns.AddColumn(column =>
{
column.PropertyName("AssetSummaryReportDetailId");
column.IsRowNumber(true);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(0);
column.Width(1);
column.HeaderCell("AssetSummaryReportDetailId");
});
columns.AddColumn(column =>
{
column.PropertyName("AssetId");
column.IsRowNumber(true);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(1);
column.Width(2);
column.HeaderCell("AssetId");
});
columns.AddColumn(column =>
{
column.PropertyName("CategoryId");
column.IsRowNumber(true);
column.CellsHorizontalAlignment(HorizontalAlignment.Center);
column.IsVisible(true);
column.Order(1);
column.Width(2);
column.HeaderCell("CategoryId");
});
})
.MainTableEvents(events =>
{
events.DataSourceIsEmpty(message: "There is no data available to display.");
})
.Export(export =>
{
// This line here should generate the Excel file, but it is not creating the Excel file
export.ToExcel(description: "Demo", fileName: "usmandemo.xlsx", worksheetName: "worksheet1", footer: "footer");
})
.Generate(data => data.AsPdfFile(string.Format("{0}\\A_RptIListSample-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));
}
答案 0 :(得分:0)
我从未使用过那个特定的库,因此无法就如何使用它提出任何建议, 但是,如果您想创建一个包含数据的xlsx文件,您可以通过其服务
来完成新的Office文件格式称为Office Open XML格式,它在所有办公应用程序之间有共同点,这里有一个MSDN指南可以帮到你