Specify how to cross string in output PDF and image
Possible Usage Scenarios
When a cell contains text or string but it is larger than the width of the cell, then the string overflows if the next cell in the next column is null or empty. When you save your Excel file into PDF/Image, you can control this overflow by specifying the cross type using the TextCrossType enumeration. It has the following values
-
TextCrossType.DEFAULT: Display text like MS Excel which depends on the next cell. If the next cell is null, the string will cross or it will be truncated.
-
TextCrossType.CROSS_KEEP: Display the string like MS Excel exporting PDF/Image
-
TextCrossType.CROSS_OVERRIDE: Display all the text by crossing other cells and override the text of crossed cells
-
TextCrossType.STRICT_IN_CELL: Only display the string within the width of the cell.
Specify how to cross string in output PDF/Image using TextCrossType
The following sample code loads the sample Excel file and saves it to PDF/Image format by specifying different TextCrossType. The sample Excel file and output files can be downloaded from the following links:
Sample Code
from aspose.cells import PdfSaveOptions, TextCrossType, Workbook | |
from aspose.cells.rendering import ImageOrPrintOptions, SheetRender | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load template Excel file | |
wb = Workbook(sourceDir + "sampleCrosssType.xlsx") | |
# Create file streams for saving the PDF and PNG files | |
with open(outputDir + "outputCrosssType.pdf", "wb") as outputStream: | |
with open(outputDir + "outputCrosssType.png", "wb") as outputStream2: | |
# Initialize PDF save options | |
saveOptions = PdfSaveOptions() | |
# Set text cross type | |
saveOptions.text_cross_type = TextCrossType.STRICT_IN_CELL | |
# Save PDF file | |
wb.save(outputStream, saveOptions) | |
# Initialize image or print options | |
imageSaveOptions = ImageOrPrintOptions() | |
# Set text cross type | |
imageSaveOptions.text_cross_type = TextCrossType.STRICT_IN_CELL | |
# Initialize sheet renderer object | |
sheetRenderer = SheetRender(wb.worksheets[0], imageSaveOptions) | |
sheetRenderer.to_image(0, outputStream2) |