Microsoft® Excel 形式変換 via .NET

Excel ファイルをスプレッドシート、Web、画像、固定レイアウト形式でインポートおよびエクスポート

 

.NET Excel ライブラリは、XLS、XLSX、XLSM、XLSB、XLTX、XLTM、CSV、SpreadsheetML、07619348 などの一般的な形式をサポートしながら、スプレッドシートのプログラミングと変換プロセスを高速化します。 1. Excel ファイルを PDF、XPS、HTML、MHTML、Plain にエクスポートすることもできます。 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 に変換

特殊なクラスを使用して、次のような特定の出力形式の変換プロセスを制御できます。 PDF保存オプション Excel ファイルを PDF としてエクスポートするには、 Xps保存オプション Excel から XPS への変換の場合、 HTML保存オプション Excel を HTML としてレンダリングし、 マークダウン保存オプション Excel から Markdown への変換用。

C# Excel から PDF および Web 形式のコード
// 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 さらに処理したり、サポートされている形式に簡単に変換したりできます。同様に、 ワークシート データは、 範囲 またはセルを呼び出して、 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 ファイルに変換することが可能です。 DocxSaveオプション & Pptx保存オプション 以下に示すようなクラス。

ExcelからWordへのC#コードと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());