Microsoft® การแปลงรูปแบบ Excel via .NET

นำเข้าและส่งออกไฟล์ Excel เป็นสเปรดชีต เว็บ รูปภาพ และรูปแบบคงที่

 

.NET Excel Library เร่งความเร็วการเขียนโปรแกรมสเปรดชีตและกระบวนการแปลงในขณะที่รองรับรูปแบบยอดนิยม ได้แก่ XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, ODS . นอกจากนี้ยังอนุญาตให้ส่งออกไฟล์ Excel ไปที่ PDF, XPS, HTML, MHTML, ธรรมดา รูปแบบข้อความและรูปภาพยอดนิยม เช่น TIFF, JPG, PNG, BMP และ SVG

แปลง Excel เป็น XLSX, ODS, SXC และ FODS

การแปลงรูปแบบสเปรดชีตระหว่างกันต้องโหลดสเปรดชีตที่มีอินสแตนซ์เท่านั้น สมุดงาน และบันทึกกลับในรูปแบบที่ต้องการพร้อมเลือกค่าที่เหมาะสมจาก บันทึกรูปแบบ การแจงนับ

C# รหัสสำหรับการแปลงรูปแบบไฟล์ Excel
// load the template file
var workbook = new Aspose.Cells.Workbook("template.xls");
// save as XLSX, ODS, SXC & FODS formats
workbook.Save("output.xlsx", Aspose.Cells.SaveFormat.Xlsx);
workbook.Save("output.ods", Aspose.Cells.SaveFormat.Ods);
workbook.Save("output.scx", Aspose.Cells.SaveFormat.Sxc);
workbook.Save("output.fods", Aspose.Cells.SaveFormat.Fods);
 

แปลง Excel เป็น PDF, XPS, HTML และ MD

มีคลาสเฉพาะทางเพื่อควบคุมกระบวนการแปลงสำหรับรูปแบบเอาต์พุตเฉพาะเช่น ตัวเลือก PdfSave เพื่อส่งออกไฟล์ Excel เป็น PDF, XpsSaveOptions สำหรับการแปลง Excel เป็น XPS HtmlSaveตัวเลือก เพื่อเรนเดอร์ Excel เป็น HTML และ MarkdownSaveOptions สำหรับการแปลง Excel เป็น Markdown

C# รหัสสำหรับ Excel ถึง PDF และรูปแบบเว็บ
// load template Excel file from disc
var book = new Aspose.Cells.Workbook("template.xlsx");
// save Excel in PDF/A-1a format
book.Save("output.pdf", new Aspose.Cells.PdfSaveOptions() { Compliance = PdfComplianceVersion.PdfA1a });
// save Excel in XPS with 1 page per worksheet
book.Save("output.xps", new Aspose.Cells.XpsSaveOptions() { OnePagePerSheet = true });
// save Excel in HTML with images as Base64
book.Save("output.html", new Aspose.Cells.HtmlSaveOptions() { ExportImagesAsBase64 = true });
// save Excel in Markdown (MD) while retaining cell formatting
book.Save("output.md", new Aspose.Cells.MarkdownSaveOptions() { FormatStrategy = Cells.CellValueFormatStrategy.CellStyle });
 

แปลง JSON เป็น Excel และ Excel เป็น JSON

JSON ข้อมูลสามารถนำเข้าไปยังอินสแตนซ์ของ Cells ชั้นเรียนด้วยความช่วยเหลือของ JsonUtility.ImportData สำหรับการประมวลผลเพิ่มเติมหรือการแปลงเป็นรูปแบบที่รองรับอย่างง่าย ในทำนองเดียวกัน ใบงาน ข้อมูลสามารถส่งออกเป็น JSON โดยการสร้าง พิสัย หรือเซลล์และเรียก JsonUtility.ExportRangeToJson วิธี.

รหัส C# สำหรับการแปลง JSON เป็น Excel
// create a Workbook object
var workbook = new Cells.Workbook();
var worksheet = workbook.Worksheets[0];
// read JSON data from file
string jsonInput = File.ReadAllText("Data.json");
// set JsonLayoutOptions to treat Arrays as Table
var options = new Cells.Utility.JsonLayoutOptions();
options.ArrayAsTable = true;
// import JSON data to worksheet starting at cell A1
Cells.Utility.JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);
// save resultant file in XLSX format
workbook.Save("output.xlsx", Cells.SaveFormat.Auto); 
C# รหัสสำหรับการแปลง Excel เป็น JSON
// load XLSX file with an instance of Workbook
var workbook = new Workbook("template.xlsx", new LoadOptions(Cells.LoadFormat.Auto));
// access CellsCollection of the worksheet containing data to be converted
var cells = workbook.Worksheets[0].Cells;
// create & set ExportRangeToJsonOptions for advanced options
var exportOptions = new Utility.ExportRangeToJsonOptions();
// create a range of cells containing data to be exported
var range = cells.CreateRange(0, 0, cells.LastCell.Row + 1, cells.LastCell.Column + 1);
// export range as JSON data
string jsonData = Cells.Utility.JsonUtility.ExportRangeToJson(range, exportOptions);
// write data file to disc in JSON format
System.IO.File.WriteAllText("output.json", jsonData); 
 

แปลงแผ่นงาน Excel เป็น JPG, BMP, PNG & GIF

แต่ละแผ่นงานของไฟล์ Excel สามารถแปลงเป็นรูปแบบภาพที่แตกต่างกันที่กำหนดโดย ImageOrPrintOptions.ImageType คุณสมบัติ. ค่าเริ่มต้นคือ ImageFormat.Bmp

C# รหัสสำหรับการแปลง Excel เป็นรูปภาพ
// load template spreadsheet
var workbook = new Aspose.Cells.Workbook("template.xlsx");
// create & set an instance of ImageOrPrintOptions
var options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.OnePagePerSheet = true;
// set output image format
options.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;
// create SheetRender for first worksheet in the collection
var render = new Aspose.Cells.Rendering.SheetRender(workbook.Worksheets[0], options);
// render worksheet to image
render.ToImage(0, "output.jpg");
 

แปลง Excel เป็น Word และ PowerPoint

คุณสามารถโหลดสเปรดชีตใดก็ได้และแปลงเป็นไฟล์ Word DOCX & PowerPoint PPTX ในขณะที่ใช้งาน DocxSaveOptions & PptxSaveOptions ชั้นเรียนตามที่แสดงด้านล่าง

รหัส C# สำหรับ Excel เป็น Word และการแปลง PowerPoint
// load the template file
var workbook = new Aspose.Cells.Workbook("template.xlsx");
// save spreadsheet as DOCX
workbook.Save("output.docx", new Aspose.Cells.DocxSaveOptions());
// save spreadsheet as PPTX
workbook.Save("output.pptx", new Aspose.Cells.PptxSaveOptions());