If text is long vertically it is not moving to next page. autofitrow() not working as expected

if i fix the column width and if text is long vertically it is not moving to next page. autofitrow() not working as expected

@royal.monteiro

To get the height of wrapped text in a cell using Aspose.Cells, you can utilize the AutoFitRows method after setting the text to be wrapped. If the row height is not adjusting as expected, follow these steps:

  1. Cause: The issue may arise from not having text wrapping enabled, incorrect auto-fitting options, or merged cells affecting the height calculation.

  2. Solution:

    • Ensure Text Wrapping is Enabled: Set the cell’s style to enable text wrapping by setting the IsTextWrapped property to true.
    • Use AutoFitterOptions: Customize the auto-fitting behavior with AutoFitterOptions to specify how the row height should be adjusted for wrapped text.
    • Check for Merged Cells: If the cell is merged with others, ensure that the auto-fitting options account for merged cells.

Here’s a minimal code example to illustrate how to set up a cell with wrapped text and auto-fit the row height:

// Create a workbook and access the first worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);

// Access a specific cell and set its value
Cell cell = worksheet.getCells().get("A1");
cell.putValue("This is a long text that should wrap in the cell.");

// Set the cell style to wrap text
Style style = cell.getStyle();
style.setTextWrapped(true);
cell.setStyle(style);

// Auto-fit the row height
worksheet.autoFitRow(0); // 0 is the index for the first row

// Save the workbook
workbook.save("output.xlsx");
  1. Next Steps: If you continue to experience issues, ensure that you are using the latest version of Aspose.Cells, as updates may include fixes for such behaviors. Additionally, review your implementation to confirm that all steps are correctly followed.

Please let me know if this resolves your issue!

no same issue

@royal.monteiro,

Could you please share a sample (runnable) code snippet along with a sample Excel file (if applicable) to help us reproduce the issue on our end? We will look into your issue soon.

P.S. Kindly ensure the Excel file is zipped before attaching it here.

using Aspose.Cells;
using System;

class Program
{
static void Main()
{
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];

	string longText = "Once upon a time, in a world where imagination knew no boundaries, where the sky was painted in hues of lavender and gold, where the wind whispered secrets through the trees, where dreams danced across rivers of crystal-clear water, where mountains stood like silent guardians over the valleys below, where animals spoke in riddles and sang songs of ancient wisdom, where time bent gently around moments of joy, sorrow, courage, and discovery, there lived a young dreamer named Elian, who, with eyes like polished amber and a heart full of yearning, embarked on a journey not for fame or fortune, but for truth, for understanding, for that shimmering thread of meaning woven into the vast tapestry of life, for he believed, with the conviction only the innocent and curious possess, that somewhere beyond the horizon, beyond the edge of maps and the reach of known stars, lay a secret, a whisper, a truth unspoken, a truth that could mend broken hearts, heal wounded lands, and restore balance to a world that had begun to forget the quiet power of kindness, the strength of hope, the value of listening, the importance of patience, and the necessity of unity, and so, he set forth, not with an army, not with a sword, not with riches, but with a journal, a quill, a satchel of dried fruit, and the blessings of his village elders, who, though aged and wary, saw in his eyes the flicker of something rare, something brave, something pure, and Elian traveled across forests thick with fog, across deserts shimmering with heat, through cities that pulsed with electric energy and whispered tales in neon, across seas that roared with the fury of forgotten gods, through mountain passes so narrow and steep that each step felt like a question to the universe, and as he traveled, he listened to stories told by farmers beneath the moon, by children at play beneath sun-dappled canopies, by merchants sipping spiced tea in crowded bazaars, by monks meditating on windswept cliffs, by widows mourning beside candlelit altars, and he collected these stories, not to claim them, not to use them, but to learn, to connect, to understand, and slowly, like a tree growing from seed to sapling to strength, he began to see patterns, began to see how all people, though different in tongue, dress, belief, and song, shared common threads—fear of loss, longing for love, desire for peace, hunger for purpose, need for belonging—and the more he listened, the more he saw, the more he saw, the more he understood, and the more he understood, the more he loved, not in the way of fleeting romance or shallow affection, but in the way of deep compassion, the kind that transcends difference, that sees beyond skin and status and history, the kind that builds bridges across silence, and so he became known, not as a hero or a warrior, but as a witness, a wayfarer of wisdom, a gatherer of truth, and his name passed in whispers from one village to the next, not because he demanded it, but because his presence lingered like perfume, like song, like memory, and in the twilight of one long day, as he stood atop a hill overlooking a land bathed in golden light, he realized he had become what he had sought, not by conquering, but by surrendering, not by preaching, but by listening, not by taking, but by giving, and he understood then that the truth he sought was not a destination, not a treasure to be locked away, but a journey, a practice, a daily choice to see, to feel, to connect, to forgive, to remember that in every stranger is a story, in every story is a lesson, and in every lesson, a seed of peace, and so Elian continued, not because he had to, but because he knew the world needed such journeys, needed reminders that stories matter, that listening heals, that kindness ripples, and though he never returned to the village of his birth, his legend lived on in the hearts of those who heard the stories he carried, in the songs sung by travelers around fires, in the writings etched into stone walls and old books, and some say he still walks, somewhere far beyond the edge of what we know, still listening, still learning, still loving, carrying the eternal sentence of life forward—one word, one person, one story at a time.";

	var cell = sheet.Cells["A1"];
	cell.PutValue(longText);

	Style style = cell.GetStyle();
	style.IsTextWrapped = true;
	cell.SetStyle(style);

	sheet.Cells.SetColumnWidthPixel(0, 200);
	sheet.AutoFitRow(0);
	sheet.PageSetup.Orientation = PageOrientationType.Landscape;
	// Save as PDF
	workbook.Save("output.pdf", SaveFormat.Pdf);
	Console.WriteLine("PDF saved successfully.");
}

}

if the text is very long it does not go to next page
output.pdf (35.9 KB)

@royal.monteiro,

Thanks for the PDF file and code snippet.

I tested your scenario using the sample code snippet you provided. It appears that the behavior you’re observing is not an issue with Aspose.Cells but rather a limitation inherent to Microsoft Excel (see the document: Excel Specifications and Limits|Documentation). Aspose.Cells adheres to Microsoft Excel’s standards and specifications when generating Excel files and rendering them to PDF. To verify this, you can save the output to an Excel file (by adding a line at the end to save it in XLSX format). Then, manually open the Excel file generated by Aspose.Cells and save it as a PDF. You will notice that the long text is clipped and does not automatically move the rest of the content to the next page.

To address your requirements, you might consider splitting the long text into multiple cells or increasing the column width (e.g., to 810 pixels) to ensure all the data is displayed properly. You may replace the line:

sheet.Cells.SetColumnWidthPixel(0, 200);

with:

sheet.Cells.SetColumnWidthPixel(0, 810);

and it will work as no data is clipped and the whole data is visible/displayed in the output files (PDF, XLSX).