Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.SetColumnWidthPixel(0, 14);
Console.WriteLine(worksheet.Cells.GetColumnWidthPixel(0));
The output: this work ok but excel inside not work.
14
Latest version v25.6 using the following sample zip with output file or code
OUTPUT.zip (13.4 KB)
@imparthgalani
Cause
You are experiencing an issue with setting the column width in pixels using Aspose.Cells. While your code correctly sets the column width and retrieves the expected value, the actual display in Excel may not reflect this change as intended.
Solution
To ensure that the column width is set correctly and displayed as expected in Excel, use the SetColumnWidth
method instead of SetColumnWidthPixel
. The SetColumnWidth
method allows you to specify the width in character units, which Excel interprets more reliably.
Code
Here’s how you can modify your code:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// Set the column width in character units
worksheet.Cells.SetColumnWidth(0, 14); // Adjust this value as needed
Console.WriteLine(worksheet.Cells.GetColumnWidth(0)); // This will return the width in character units
Next Steps
- Test the modified code to see if the column width appears correctly in Excel.
- If the issue persists, check the Excel file format you are saving to, as some formats may have limitations regarding column width.
- Ensure that you are using the latest version of Aspose.Cells, as updates may contain fixes for such issues.
Please try these steps and let me know if you need further assistance!
Using this code when set to 14px and output of Excel column width as 102px, please see image below
image.png (58.7 KB)
Using this proper column width set. thanks for helping me.
// Apply font style to all cells
Style style = workbook.CreateStyle();
// Set desired properties on the style
style.Font.Name = “游ゴシック”;
style.Font.Size = 9;
style.Font.SchemeType = FontSchemeType.None;
workbook.DefaultStyle = style;
@imparthgalani ,
It seems that your issue is sorted out. Your similar topic is figured at Column width in pixels set issue .
Yes, the issue is sorted out. Thanks for your help.
@imparthgalani
Thank you for your feedback. You are welcome. If you have any questions, please feel free to contact us at any time.