Zeilenumbrüche und Textumbruch
Contents
[
Hide
]
Um sicherzustellen, dass der Text in einer Zelle gelesen werden kann, können explizite Zeilenumbrüche und Textumbrüche angewendet werden. Textumbrüche verwandeln eine Zeile in mehrere in einer Zelle, wobei explizite Zeilenumbrüche genau dort eingefügt werden, wo Sie sie haben möchten.
Text in einer Zelle umbrechen
Um Text in einer Zelle umzubrechen, verwenden Sie die Aspose.Cells.Style.setIsTextWrapped(boolean) Methode.
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
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create Workbook Object | |
const wb = new AsposeCells.Workbook(); | |
// Open first Worksheet in the workbook | |
const ws = wb.getWorksheets().get(0); | |
// Get Worksheet Cells Collection | |
const cell = ws.getCells(); | |
// Increase the width of First Column Width | |
cell.setColumnWidth(0, 35); | |
// Increase the height of first row | |
cell.setRowHeight(0, 36); | |
// Add Text to the First Cell | |
cell.checkCell(0, 0).putValue("I am using the latest version of Aspose.Cells to test this functionality"); | |
// Make Cell's Text wrap | |
const style = cell.checkCell(0, 0).getStyle(); | |
style.setIsTextWrapped(true); | |
cell.checkCell(0, 0).setStyle(style); | |
// Save Excel File | |
wb.save(path.join(dataDir, "WrappingText.out.xlsx")); |
Explizite Zeilenumbrüche verwenden
Sie können ‘\n’ in JavaScript verwenden, um in einer Zelle explizite Zeilenumbrüche einzufügen.
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
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create Workbook Object | |
const wb = new AsposeCells.Workbook(); | |
// Open first Worksheet in the workbook | |
const ws = wb.getWorksheets().get(0); | |
// Get Worksheet Cells Collection | |
const cell = ws.getCells(); | |
// Increase the width of First Column Width | |
cell.setColumnWidth(0, 35); | |
// Increase the height of first row | |
cell.setRowHeight(0, 65); | |
// Add Text to the First Cell with Explicit Line Breaks | |
cell.checkCell(0, 0).putValue("I am using\nthe latest version of \nAspose.Cells to \ntest this functionality"); | |
// Make Cell's Text wrap | |
const style = cell.checkCell(0, 0).getStyle(); | |
style.setIsTextWrapped(true); | |
cell.checkCell(0, 0).setStyle(style); | |
// Save Excel File | |
wb.save(path.join(dataDir, "WrappingText.out.xlsx")); |