自 VintaSoft Imaging .NET SDK 10.1 版以来,可以以编程方式编辑现有的 DOCX 和 XLSX 文档。本文使用此功能创建一个简单且易于定制的 XLSX 文档格式的价目表生成器。
VintaSoftImaging.NET SDK是一个为.NET开发人员开发的,强大而易于使用的图像工具包。它可以让你加载、查看、处理、打印和保存数字图像,可将它们转换为不同的图像格式,可用多种TIFF和动态GIF文件提高您的工作效率。
【VintaSoftImaging.NET SDK下载】
通常,价目表是包含商品或服务信息(描述、照片、数量、价格)的表格。对于此类表的表示非常适合 XLSX 格式。
自 VintaSoft Imaging .NET SDK 10.1 版以来,可以以编程方式编辑现有的 DOCX 和 XLSX 文档。可以使用此功能创建一个简单且易于定制的 XLSX 文档格式的价目表生成器。
执行以下步骤以创建 XLSX 文档格式:
价目表生成器:
- 使用 MS Excel 创建文档模板 (Pricelist_template.xlsx)。
- 编写用动态数据填充模板的编程代码。
以下代码显示了如何创建价目表并将其保存到 XLSX 文档:
// 使用此代码的项目必须引用以下程序集:// - Vintasoft.Imaging// - Vintasoft.Imaging.Office.OpenXml/// <summary>/// 生成基于 XLSX 文档模板的 XLSX 价目表。/// </summary>public static void GenerateXlsxPricelist(){ //创建XLSX文档编辑器和使用文件“Pricelist_template.xlsx”作为文档模板 使用(Vintasoft.Imaging.Office.OpenXml.Editor。XlsxDocumentEditor编辑器= 新Vintasoft.Imaging.Office.OpenXml.Editor。XlsxDocumentEditor(“Pricelist_template.xlsx” )) { // 生成测试价目表数据 PriceListItem[] testData = GetTestData(); // 填写价目表数据 FillPricelistData(editor, testData); // 将价格表保存到 XLSX 文档 editor.Save( " Pricelist.xlsx " ); }}/// <summary>/// 使用 XLSX 文档编辑器填充价目表数据。/// </summary>/// <param name="documentEditor">DOCX 文档编辑器。</param>/// <param name="pricelistData">价目表数据。</param>private static void FillPricelistData ( Vintasoft.Imaging.Office.OpenXml.Editor。XlsxDocumentEditor文档编辑器, PriceListItem[] pricelistData){ // 在文档中设置当前日期 documentEditor.Body[ "[date]" ] = System. 日期时间.Now.ToShortDateString(); // 获取文档 Vintasoft.Imaging.Office.OpenXml.Editor 中的第一张工作表。XlsxDocumentSheet sheet = documentEditor.Sheets[0]; // 获取文档 Vintasoft.Imaging.Office.OpenXml.Editor 中的模板行。XlsxDocumentSheetRow templateRow = sheet.FindRow( "[n]" ); int itemNumber = 1; // 对于价目表中的每一项 foreach (PriceListItem item in pricelistData ) { // 复制模板行并在模板行后插入副本 Vintasoft.Imaging.Office.OpenXml.Editor. XlsxDocumentSheetRow currentRow = templateRow; templateRow =(Vintasoft.Imaging.Office.OpenXml.Editor。XlsxDocumentSheetRow)templateRow.InsertCopyAfterSelf(); // 填充当前行的数据 currentRow.FindCell( "[n]" ).Number = itemNumber; currentRow.FindCell( "[产品]" ).Text = item.Product; currentRow.FindCell( "[价格]" ).Number = item.Price; // 获取当前行中存储产品图片的图片对象 Vintasoft.Imaging.Office.OpenXml.Editor. OpenXmlDocumentImage image = sheet.FindImages(currentRow)[0]; // 如果产品有图片 if (! string .IsNullOrEmpty(item.ImageId)) { 在图像对象//集产品图像 使用(Vintasoft.Imaging。VintasoftImage productImage =新Vintasoft.Imaging。VintasoftImage(item.ImageId)) image.SetImage(productImage, true ); } 别的 { // 从当前行移除图像对象 图像.移除(); } 项目编号++; } // 从结果文档中删除模板行 templateRow.Remove();}/// <summary>/// 返回价目表测试数据。/// </summary>/// <returns>价格表测试数据。</returns>public static PriceListItem[] GetTestData(){ return new PriceListItem[] { new PriceListItem( "VintaSoft Imaging .NET SDK, Developer license for Desktop PCs" , "vsimaging-icon.png" , 219.95f), new PriceListItem( "VintaSoft Imaging .NET SDK, Developer license for Servers" , "vsimaging-icon.png" , 549.95f), new PriceListItem( "VintaSoft Imaging .NET SDK, Site license for Desktop PCs" , "vsimaging-icon.png" , 659.95f), new PriceListItem( "VintaSoft Imaging .NET" SDK,服务器站点许可”,“vsaging-icon.PNG", 1649.95f), new PriceListItem( "VintaSoft Imaging .NET SDK, Single Server license" , "vsimaging-icon.png" , 164.95f), new PriceListItem( "VintaSoft Annotation .NET Plug-in, Site license for Desktop PCs" , "vsannotation-icon.png" , 449.95f), new PriceListItem( "VintaSoft Office .NET Plug-in, Site license for Desktop PCs" , "vsoffice-icon.png" , 569.95f), new PriceListItem( "VintaSoft PDF .NET Plug-in (Reader+Writer), 台式电脑站点许可" , "vspdf-icon.png" , 1499.95f),新PriceListItem( "VintaSoft PDF .NET Plug-in (Reader+Writer+VisualEditor), Site license for Desktop PCs" , "vspdf-icon.png" ,2999.95f), new PriceListItem( "VintaSoft JBIG2 .NET Plug-in, Site台式电脑许可证” , “vsjbig2-icon.png” ,1139.95f), new PriceListItem( “VintaSoft JPEG2000 .NET 插件, 台式电脑站点许可证” , “vsjpeg2000-icon.png” , 689.95f), new PriceListItem( "VintaSoft Document Cleaup .NET Plug-in, Site license for Desktop PCs" , "vsdoccleanup-icon.png" , 569.95f), 新的价目表项目("VintaSoft OCR .NET 插件,台式电脑的站点许可证","vsocr-icon.png",509.95f), 新的PriceListItem( "VintaSoft DICOM .NET 插件(编解码器+MPR),台式机的站点许可证) " , "vsdicom-icon.png" , 1199.95f), new PriceListItem( "VintaSoft Forms Processing .NET Plug-in, Site license for Desktop PCs" , "vsformsprocessing-icon.png" , 509.95f), new PriceListItem( " VintaSoft Barcode .NET SDK (1D+2D Reader+Writer), 台式电脑站点许可" , "vsbarcode-icon.png" , 1379.95f), 新的价目表项目("VintaSoft Twain .NET SDK, Developer license" , "vstwain-icon.png" , 179.95f), new PriceListItem( "VintaSoft Twain .NET SDK, Site license" , "vstwain-icon.png" , 539.95f), new PriceListItem( "VintaSoft Twain .NET SDK, Single URL license" , "vstwain-icon.png" , 149.95f), new PriceListItem( "VintaSoft Twain ActiveX, Developer license" , "vstwain-icon.png" , 99.95f), new PriceListItem( "VintaSoft Twain ActiveX, 站点许可证" , "vstwain-icon.png" , 299.95f), new PriceListItem( "VintaSoft Twain ActiveX, Single URL license" , "vstwain-icon.png" , 119.95f) };}/// <summary>/// 代表一个价目表项目。/// </summary>公共 类PriceListItem{ /// <summary> /// 初始化 <see cref="PriceListItem"/> 类的新实例。 /// </summary> /// <param name="product">产品名称。</param> /// <param name="imageId">图像ID。</param> /// <param name="price">产品价格。</param> public PriceListItem( string product, string imageId, float price) { 产品 = 产品; ImageId = imageId; 价格 = 价格; } /// <summary> /// 获取产品名称。 /// </summary> 公共 字符串产品; /// <summary> /// 获取图像 ID。 /// </summary> 公共 字符串ImageId; /// <summary> /// 获取产品价格。 /// </summary> 公开 浮动价格;}
购买最新正版授权!”咨询在线客服“
年终盛典火爆开启,一年仅一次的最强促销,十八周年盛“惠”不容错过!!优惠详情点击查看>>
标签:
来源:慧都
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!