出力PDFおよびイメージで文字列をクロスする方法を指定します。

可能な使用シナリオ

セルにテキストが含まれているが、セルの幅を超える場合、次の列の次のセルがnullまたは空の場合、文字列がオーバーフローします。 ExcelファイルをPDF /イメージに保存する際、このオーバーフローを制御することができます。これはTextCrossType列挙型を使用して、クロスタイプを指定することで可能です。以下の値が含まれます

  • TextCrossType.Default: 次のセルに依存するようにMS Excelのようにテキストを表示します。次のセルがnullの場合、文字列が交差するか、切り捨てられます。

  • TextCrossType.CrossKeep: MS ExcelでPDF /イメージをエクスポートしたように文字列を表示します。

  • TextCrossType.CrossOverride: すべてのテキストを表示して、他のセルを交差して上書きします

  • TextCrossType.StrictInCell: セルの幅内で文字列のみを表示します。

TextCrossTypeを使用して出力PDF/イメージで文字列をクロスする方法を指定します。

以下のサンプルコードは、さまざまなTextCrossTypeを指定してサンプルExcelファイルをロードし、PDF/イメージ形式で保存するものです。 サンプルExcelファイルと出力ファイルは、以下のリンクからダウンロードできます。

sampleCrossType.xlsx

outputCrossType.pdf

outputCrossType.png

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Load template Excel file
Workbook wb = new Workbook(sourceDir + "sampleCrosssType.xlsx");
// Create file streams for saving the PDF and PNG files
using (FileStream outputStream = new FileStream(outputDir + "outputCrosssType.pdf", FileMode.Create))
using (FileStream outputStream2 = new FileStream(outputDir + "outputCrosssType.png", FileMode.Create))
{
// Initialize PDF save options
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Set text cross type
saveOptions.TextCrossType = TextCrossType.StrictInCell;
// Save PDF file
wb.Save(outputStream, saveOptions);
// Initialize image or print options
ImageOrPrintOptions imageSaveOptions = new ImageOrPrintOptions();
// Set text cross type
imageSaveOptions.TextCrossType = TextCrossType.StrictInCell;
// Initialize sheet renderer object
SheetRender sheetRenderer = new SheetRender(wb.Worksheets[0], imageSaveOptions);
// Create bitmap image from sheet renderer
System.Drawing.Bitmap bitmap = sheetRenderer.ToImage(0);
// Save PNG image
bitmap.Save(outputStream2, ImageFormat.Png);
}