ExcelをPdf、Image、その他の形式に変換する
ExcelワークブックをPDFに変換
PDFファイルは、組織、政府部門、個人間で文書を交換するために広く使用されています。これは標準のドキュメント形式であり、ソフトウェア開発者はしばしばMicrosoft ExcelファイルをPDFドキュメントに変換する方法を見つけるよう求められます。
Aspose.Cellsは、ExcelファイルをPDFに変換する機能をサポートし、変換時に高い視覚的忠実度を維持します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiate the Workbook object | |
// Open an Excel file | |
Workbook workbook = new Workbook("Book1.xlsx"); | |
// Save the document in PDF format | |
workbook.Save("output.pdf"); |
ExcelワークブックをJPGに変換
Aspose.CellsはExcelファイルをJPGに変換することをサポートしています。 以下のコード例は、ブックをJPG形式で保存する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open a template excel file | |
Workbook book = new Workbook("Book1.xlsx"); | |
//Convert workbook to JPG image. | |
book.Save("Image1.jpg"); |
Excelブックを画像に変換する
Aspose.CellsはExcelファイルを画像に変換することをサポートしています。 以下のコード例は、ブックを画像として保存する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open a template excel file | |
Workbook book = new Workbook("Book1.xlsx"); | |
//Convert workbook to BMP image. | |
book.Save("Image1.bmp"); | |
//Convert workbook to JPG image. | |
book.Save("Image1.jpg"); | |
//Convert workbook to Png image. | |
book.Save("Image1.png"); | |
//Convert workbook to EMF image. | |
book.Save("Image1.emf"); | |
//Convert workbook to GIF image. | |
book.Save("Image1.gif"); |
ExcelブックをXPSに変換する
XPS文書形式は、文書のレイアウトと各ページの外観、配布、アーカイブ、レンダリング、処理、印刷に関するレンダリング規則を定義する構造化されたXMLマークアップで構成されています。
XPSのマークアップ言語はXAMLのサブセットで、Windows Presentation Foundation(WPF)のプリミティブをマークアップするためにベクトルグラフィックス要素を組み込むことができます。使用される要素はパスや他の幾何学的プリミティブで記述されています。
XPSファイルは、実際には、文書を構成するファイルを含むOpen Packaging Conventionsを使用するユニコードZIPアーカイブであり、各ページのためのXMLマークアップファイル、テキスト、埋め込みフォント、ラスタ画像、2Dベクトルグラフィック、およびデジタル著作権管理情報が含まれています。XPSファイルの内容は、ZIPファイルをサポートするアプリケーションで開くことで簡単に調べることができます。
Aspose.Cells 6.0.0以降、Microsoft ExcelからXPSへの変換がサポートされています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an Excel file | |
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(dataDir + "Book1.xls"); | |
// Get the first worksheet | |
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0]; | |
// Apply different Image and Print options | |
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
// Set the Format | |
options.SaveFormat = SaveFormat.Xps; | |
// Render the sheet with respect to specified printing options | |
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, options); | |
// Save | |
sr.ToImage(0, dataDir + "out_printingxps.out.xps"); | |
// Export the whole workbook to XPS | |
workbook.Save(dataDir + "out_whole_printingxps.out.xps", new XpsSaveOptions()); |
ExcelをOds、Sxc、Fods(OpenOffice / LibreOffice Calc)に変換する
Aspose.CellsはExcelファイルをOds、Sxc、Fodsファイルに変換することをサポートしています。以下のコード例は、tempalteをOds、Sxc、Fodsファイルに変換する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load your source workbook | |
Workbook workbook = new Workbook("book1.xlsx"); | |
// Save as ods file | |
workbook.Save("Out.ods"); | |
// Save as sxc file | |
workbook.Save("Out.sxc"); | |
// Save as fods file | |
workbook.Save("Out.fods"); |
ExcelワークブックをMHTMLファイルに変換する
MHTMLは通常のHTMLと外部リソース(通常はリンクされた画像、アニメーション、オーディオなどのコンテンツ)を1つのファイルに組み合わせたものです。.mhtファイル拡張子を持つ電子メールで使用されています。
Aspose.CellsはMHTMLファイルの読み書きをサポートしています。
以下のコード例は、ワークブックをMHTMLファイルとして保存する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the file path | |
string filePath = dataDir + "Book1.xlsx"; | |
// Specify the HTML Saving Options | |
HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.MHtml); | |
// Instantiate a workbook and open the template XLSX file | |
Workbook wb = new Workbook(filePath); | |
// Save the MHT file | |
wb.Save(filePath + ".out.mht", sv); |
ExcelワークブックをHTMLに変換する
Aspose.Cells APIは、スプレッドシートをHTML形式にエクスポートするサポートを提供しています。このため、Aspose.CellsはHtmlSaveOptionsクラスを使用して出力されるHTMLのいくつかの側面を制御する柔軟性を提供しています。
以下のコード例は、ブックをHTMLファイルとして保存する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the file path | |
string filePath = dataDir + "sample.xlsx"; | |
// Load your sample excel file in a workbook object | |
Workbook wb = new Workbook(filePath); | |
// Save it in HTML format | |
wb.Save(dataDir + "ConvertingToHTMLFiles_out.html", SaveFormat.Html); |
HTMLの画像設定を設定する
8.0.2以降、Aspose.CellsはHtmlSaveOptionsクラスのためのImageOptionsを公開し、スプレッドシートをHTML形式に保存する際に開発者がイメージ設定を指定できるようにしています。
適用できるいくつかの画像設定の詳細は以下のとおりです。
- ImageType:画像タイプを指定します。すべての形状(チャートを含む)は、出力HTMLでは画像としてレンダリングされることに注意してください。
- SmoothingMode:線、曲線、塗りつぶしエリアのアンチエイリアシングを指定します。
- TextRenderingHint:テキストのレンダリング品質を指定します。
- Quality:Jpegを指定すると0から100までの画像品質を指定します。
- VerticalResolution:画像の垂直解像度(dpi)を取得または設定します。
- HorizontalResolution:画像の水平解像度(dpi)を取得または設定します。
- TiffCompression:Tiffを指定すると画像の圧縮タイプを取得または設定します。
- Transparent:ImageFormatをPngと指定すると、画像の背景が透明にするかどうか示します。
以下のコードは、HtmlSaveOptions.ImageOptionsを使用して異なる設定を指定する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specify the file path | |
string filePath = dataDir + "Book1.xlsx"; | |
// Load a spreadsheet to be converted | |
Workbook book = new Workbook(filePath); | |
// Create an instance of HtmlSaveOptions | |
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html); | |
// Set the ImageFormat to PNG | |
saveOptions.ImageOptions.ImageType = Drawing.ImageType.Png; | |
// Set SmoothingMode to AntiAlias | |
saveOptions.ImageOptions.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; | |
// Set TextRenderingHint to AntiAlias | |
saveOptions.ImageOptions.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; | |
// Save spreadsheet to HTML while passing object of HtmlSaveOptions | |
book.Save( dataDir + "output.html", saveOptions); | |
ExcelブックをMarkdownに変換する
Aspose.Cells APIは、スプレッドシートをMarkdown形式にエクスポートするサポートを提供しています。アクティブなワークシートをMarkdownにエクスポートするには、Workbook.Saveメソッドの第2パラメータとしてSaveFormat.Markdownを渡します。また、ワークシートをMarkdownにエクスポートするための追加の設定を指定するには、MarkdownSaveOptionsクラスを使用できます。
以下のコード例は、SaveFormat.Markdown列挙型のメンバーを使用してアクティブなワークシートをMarkdownにエクスポートする方法を示しています。生成されたコードの参照用に、出力Markdownファイルをご覧ください。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template file | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
// Save as Markdown | |
workbook.Save(outputDir + "Book1.md", SaveFormat.Markdown); |
ExcelワークブックをJSONに変換
Aspose.CellsはワークブックをJSON(JavaScript Object Notation)ファイルに変換する機能をサポートしています。
次のコード例は、アクティブワークシートをSaveFormat.Json列挙型メンバーを使用してJSONにエクスポートする方法を示しています。参照のために、コードによって生成された出力JSONファイルに変換するソースファイルをご覧ください。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load your source workbook | |
Workbook workbook = new Workbook("Book1.xlsx"); | |
// convert the workbook to json file. | |
workbook.Save(dir + "book1.json"); |
ExcelをXMLに変換
Aspose.Cellsは、ワークブックをExcel 2003スプレッドシートXMLおよびプレーンXMLデータに変換することをサポートしています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load your source workbook | |
Workbook workbook = new Workbook("Book1.xlsx"); | |
//Save as Excel 2003 Spreadsheet XML | |
workbook.Save("Spreadsheet.xml"); | |
//Save as plain XML data | |
XmlSaveOptions xmlSaveOptions = new XmlSaveOptions(); | |
workbook.Save("data.xml", xmlSaveOptions); |
ExcelブックをTIFFに変換する
Aspose.Cellsは、ワークブックをTIFFファイルに変換することをサポートしています。
以下のコードスニペットは、ExcelをTIFFに変換する方法を示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open a template excel file | |
Workbook book = new Workbook("Book1.xlsx"); | |
//save file to tiff | |
book.Save("out.tiff"); |
ExcelブックをDOCXに変換する
Aspose.Cells APIは、スプレッドシートをDOCX形式に変換するサポートを提供しています。ワークブックをDOCXにエクスポートするには、Workbook.Saveメソッドの第2パラメータとしてSaveFormat.Docxを渡します。また、ワークシートをDOCXにエクスポートするための追加の設定を指定するには、DocxSaveOptionsクラスを使用できます。
次のコード例は、アクティブワークシートをSaveFormat.Docx列挙型メンバーを使用してDOCXにエクスポートする方法を示しています。参照のために、コードによって生成された出力DOCXファイルをご覧ください。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template file | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
// Save as Markdown | |
workbook.Save(outputDir + "Book1.docx", SaveFormat.Docx); |
ExcelブックをPPTXに変換する
Aspose.Cells APIは、スプレッドシートをPPTX形式に変換するためのサポートを提供します。ワークブックをPPTXにエクスポートするには、Workbook.Saveメソッドの第2パラメーターとしてSaveFormat.Pptxを渡します。ワークシートをPPTXにエクスポートする追加の設定を指定するには、PptxSaveOptionsクラスを使用できます。
次のコード例は、アクティブワークシートをSaveFormat.Pptx列挙型メンバーを使用してPPTXにエクスポートする方法を示しています。参照のために、コードによって生成された出力PPTXファイルをご覧ください。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template file | |
Workbook workbook = new Workbook(sourceDir + "Book1.xlsx"); | |
// Save as Markdown | |
workbook.Save(outputDir + "Book1.pptx", SaveFormat.Pptx); |