Excel Column Formatting

Hi,

I created excel (Xlsx) using XlsIO. But the columns need formatting.

1- How can I set the width of all the columns in the Sheet according to the content?

2- How can I set an entire column as a numeric value?

I want to display the value which is currently 6.8026E+12 as 6802595905700.

3- How can I format an entire column containing both numeric and text type data as text type.


Attachment: excel_5649d719.zip

1 Reply 1 reply marked as answer

RS Ramya Sivakumar Syncfusion Team June 24, 2022 02:33 PM UTC

Hi John,


Greetings from Syncfusion.


Query

Response

 

How can I set the width of all the columns in the Sheet according to the content?

Please use the AutofitColumn option to set the column width based on the content.

 

Kindly refer to the following link to know more about the AutofitColumn option.

 

https://help.syncfusion.com/file-formats/xlsio/worksheet-rows-and-columns-manipulation?cs-save-lang=1&cs-lang=csharp

How can I set an entire column as a numeric value?

 

To set the Entire column as numeric value, please use the Number Format option.

 

worksheet.Columns[0].NumberFormat = "#";

 

https://help.syncfusion.com/file-formats/xlsio/working-with-cell-or-range-formatting#apply-number-formats

 

I want to display the value which is currently 6.8026E+12 as 6802595905700.

 

If you enter the value 6802595905700 then it is converted as the 6.8026E+12 it is the MS Excel behavior.

 

To avoid this, you can set the value as string then the entire value is displayed in the cell.

 

worksheet.Range["A2"].Text = "6802595905700";

How can I format an entire column containing both numeric and text type data as text type.

Please set the Number format as Text to format the entire column as text type.

 

worksheet.Columns[0].NumberFormat = "@";



Regards,

Ramya.


Marked as answer
Loader.
Up arrow icon