指定如何在输出 PDF 和图像中交叉字符串
Contents
[
Hide
]
可能的使用场景
当单元格包含文本或字符串但大于单元格的宽度时,如果下一列中的下一个单元格为 null 或为空,则字符串会溢出。当您将 Excel 文件保存到 PDF/Image 时,您可以通过使用文本交叉类型枚举。它具有以下值
-
TextCrossType.Default: 显示文本,如 MS Excel,取决于下一个单元格。如果下一个单元格为空,则字符串将交叉或被截断。
-
文本交叉类型.CrossKeep显示像 MS Excel 导出的字符串 PDF/Image
-
文本交叉类型.CrossOverride: 跨过其他单元格显示所有文本,并覆盖跨过单元格的文本
-
TextCrossType.StrictInCell:只显示单元格宽度内的字符串。
指定如何使用 TextCrossType 在输出 PDF/Image 中交叉字符串
下面的示例代码通过指定不同的方式载入示例Excel文件并保存为PDF/Image格式文本交叉类型.示例 Excel 文件和输出文件可从以下链接下载:
示例代码
This file contains 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-.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); | |
} |