newdcm.Office 2.0.1

dotnet add package newdcm.Office --version 2.0.1
                    
NuGet\Install-Package newdcm.Office -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="newdcm.Office" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="newdcm.Office" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="newdcm.Office" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add newdcm.Office --version 2.0.1
                    
#r "nuget: newdcm.Office, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package newdcm.Office@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=newdcm.Office&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=newdcm.Office&version=2.0.1
                    
Install as a Cake Tool

1 常用的办公文档(如Excel,Word,Pdf)的生成或处理类

1.1 ExcelHelper类:将DataTable对象导出为Excel文件(Stream)

将DataTable对象生成Excel文件,返回MemoryStream(支持多个DataTable生成到Excel的多个子表)

    //只一个子表
	DataTable dtSource = db.GetDataTable("select * from dict"); //此处仅示例获取datatable
	string titleRowText = "某某时段统计报表"; // 表格内容第一行标题
	string subTitle = "统计时段:202601 - 202603"; //副标题
	bool showTitleRow = true; //显示标题行与副标题行到Excel表内容中
	bool showTableHeader = true; //是否加入表头行(列名行)
	string excelCompany = "公司名"; //Excel文件属性公司名
	string excelAuthor = "作者"; //Excel文件属性作者
	string excelAppName = "应用名称"; //Excel文件属性生成程序
	string excelTitle = "文件属性标题"; //Excel文件属性标题
	string excelSubTitle = "文件属性副标题" //Excel文件属性副标题
    MemoryStream ms = ExcelHelper.Export(dtSource,titleRowText,subTitle,showTitleRow,showTableHeader,excelCompany,excelAuthor,excelAppName,excelTitle,excelSubTitl);

	//一个Excel中带多个子表
	DataTable dtSource1 = db.GetDataTable("select * from dict"); 
	DataTable dtSource2 = db.GetDataTable("select * from items"); 
	MemoryStream ms = ExcelHelper.ExportMutipleTables(new List<DataTable>(){dtSource1,dtSource2},titleRowText,subTitle,showTitleRow,showTableHeader,excelCompany,excelAuthor,excelAppName,excelTitle,excelSubTitl);

1.2 ReportPrintTplt与ReportPrintTpltEngine类:报告打印模板生成与绑定

从vs report design生成的xml模板文件中解析出模板,绑定字段对象后,生成html打印内容

    string tpltPath = "d:\report.xml"; //模板中的字段要与下方类的属性名相同
	MyRISReport model = new MyRISReport(){ Id = 1,Name = "张三"}; //这个类或对象结构可自定义
	ReportPrintTpltEngine engine = new ReportPrintTpltEngine(tpltPath);
	ReportPrintTplt tplt = engine.ReadXmlTemplate()[0];
	tplt.BindModel(model);
	string htmlGenerate = tplt.ToString(); //生成了html
	// ViewBag.Report = ReportHtml;

1.3 PdfGenerateHelper类:使用FastReport.OpenSource的frx模板绑定数据模型,生成Pdf或html

将数据模型对象绑定到frx模型的对应控件,并生成html内容或pdf供下载

  PdfGenerateHelper helper = new PdfGenerateHelper();
  string tpltFrx = "D:\\tplt\\reportDemo.frx"; 
  MyClass model = new MyClass(){ Id = 1, Name = "Yang", Photo = "/pic/yang.jpg" }; //这个DTO模型自行定义
  strint htmlContent = helper.GetHtmlContent<MyClass>(model,tpltFrx);
  // 在webapi中,可以这样返回html: return Content(htmlContent, "text/html");
  MemoryStream pdfMs = helper.GetMemoryStream<MyClass>(model,tpltFrx);
  byte[] pdfBuffers = helper.GetBuffers<MyClass>(model,tpltFrx); 

注:在frx模型中,本工具类绑定的主要是控件的Text属性

TextObject类型\BarcodeObject类型的控件:指定Text属性的值为要绑定对象的方括号包裹的属性值。如"[Address]", PictureObject类型控件:指定ImageLocation属性值为要绑定对象方括号包裹的属性值。如"[Url]"(注:Url可以是相对本网站的地址,也可以是完整url) 如果生成pdf或html时,图片是固定图片,它必须与frx处于同一个文件夹内,并且PictureObject的Image要选中这个图片

  //以下示意frx中的部分控件绑定
  <TextObject Name = "Text2" Left="66.15" Top="18.9" Width="510.3" Height="28.35" Text="[Address]" Font="宋体, 16pt"/>
  <PictureObject Name = "Picture2" Left="170.1" Top="444.15" Width="304.44" Height="234.68" ImageLocation="[Url2]"/>

最新更新:2026-04-11 by newdcm rosiu

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 91 4/11/2026