原創|使用教程|編輯:張瑩心|2021-10-27 09:38:01.767|閱讀 249 次
概述:自 VintaSoft Imaging .NET SDK 10.1 版以來,可以以編程方式編輯現有的 DOCX 和 XLSX 文檔。本文使用此功能創建一個簡單且易于定制的 XLSX 文檔格式的價目表生成器。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
VintaSoftImaging.NET SDK是一個為.NET開發人員開發的,強大而易于使用的圖像工具包。它可以讓你加載、查看、處理、打印和保存數字圖像,可將它們轉換為不同的圖像格式,可用多種TIFF和動態GIF文件提高您的工作效率。
通常,價目表是包含商品或服務信息(描述、照片、數量、價格)的表格。對于此類表的表示非常適合 XLSX 格式。
自 VintaSoft Imaging .NET SDK 10.1 版以來,可以以編程方式編輯現有的 DOCX 和 XLSX 文檔。可以使用此功能創建一個簡單且易于定制的 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>
公開 浮動價格;
}
購買最新正版授權!""
慧都年終盛典火爆開啟,一年僅一次的最強促銷,十八周年盛“惠”不容錯過!!優惠詳情點擊查看>>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn