指定如何在输出 PDF 和图像中交叉字符串
Contents
[
Hide
]
指定如何在输出 PDF 和图像中交叉字符串
当单元格包含大于单元格宽度的文本或字符串时,如果下一列中的下一个单元格为 null 或为空,则字符串会溢出。当您将 Excel 文件保存到 PDF/Image 时,您可以通过使用文本交叉类型枚举。它具有以下值
- TextCrossType.DEFAULT: 显示类似 MS Excel,取决于下一个单元格。如果下一个单元格为空,则字符串将交叉或被截断。
- 文本交叉类型。交叉保持显示类似于MS Excel exporting PDF/Image的字符串
- TextCrossType.CROSS_OVERRIDE跨过其他单元格显示所有文本,并覆盖跨过单元格的文本
- 文本交叉类型.STRICT_在_细胞:只显示单元格宽度内的字符串。
以下示例代码加载示例 Excel 文件并通过指定不同的 TextCrossType 将其保存为 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
source_directory = "Examples/SampleFiles/SourceDirectory/" | |
output_directory = "Examples/SampleFiles/OutputDirectory/" | |
# Load the Sample Workbook | |
workbook = Workbook(source_directory + "sampleCrossType.xlsx") | |
# Initialize PDF save options | |
saveOptions = PdfSaveOptions() | |
# Set text cross type | |
saveOptions.setTextCrossType(TextCrossType.STRICT_IN_CELL) | |
# Save the excel file. | |
workbook.save(output_directory + "outputCrossType.pdf") |