画像にレンダリングする前にデータから空白を削除する
Contents
[
Hide
]
場合によっては、アプリケーションまたは Web ページでワークシート イメージを表示する必要があります。たとえば、Word ドキュメント、PDF ファイル、PowerPoint プレゼンテーション、またはその他のドキュメントに画像を挿入する必要がある場合があります。基本的に、ワークシートを画像としてレンダリングして、他のアプリケーションに貼り付けることができます。 Aspose.Cells API を使用すると、Microsoft Excel ワークシートを画像に変換できます。
のシートレンダリングクラスは、指定された属性 (イメージ形式、ページ付けされたシートなど) を持つイメージ ファイルにワークシートを変換できます。
シートから画像への機能を使用する場合、出力画像には、デフォルトで周囲に白/空白スペース、つまり境界線があります。これを削除できます。ソースワークシートの上、左、下、および右のページ設定余白を 0 に設定し、指定します。ImageOrPrintOptionsそれに応じて属性。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(RemoveWhitespaceAroundData.class) + "TechnicalArticles/"; | |
// Instantiate a workbook | |
// Open the template file | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Specify your print area if you want | |
// sheet.PageSetup.PrintArea = "A1:H8"; | |
// To remove the white border around the image. | |
sheet.getPageSetup().setLeftMargin(0); | |
sheet.getPageSetup().setRightMargin(0); | |
sheet.getPageSetup().setTopMargin(0); | |
sheet.getPageSetup().setBottomMargin(0); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
imgOptions.setImageType(ImageType.EMF); | |
// Set only one page would be rendered for the image | |
imgOptions.setOnePagePerSheet(true); | |
imgOptions.setPrintingPage(PrintingPageType.IGNORE_BLANK); | |
// Create the SheetRender object based on the sheet with its | |
// ImageOrPrintOptions attributes | |
SheetRender render = new SheetRender(sheet, imgOptions); | |
// Convert the image | |
render.toImage(0, dataDir + "RWhitespaceAroundData_out.emf"); |