Well, your code is Ok but I suspect your underlying data in the column’s cell might be of string type and not numeric data. Take an example here. When you use Cell.PutValue("-123"), it would be inserted as string type and not as numeric data type into the cell. But when you use Cell.PutValue(-123), now it is entered as numeric data type into the cell.
For your information, I used the following sample code to test your scenario/ case a bit, it works fine here. When I open the output files (XLSX into MS Excel and PDF into Acrobat reader), both shows right (formatted) data.
e.g
Sample code:
Workbook wb = new Workbook();
//Input some negative number into A1 cell.
wb.Worksheets[0].Cells[“A1”].PutValue(-2423);
int colIndex = 0;
Style style;
StyleFlag flag;
style = wb.CreateStyle();
style.Custom = “#,##0.00;Red”; //Negative numbers in parenthesis with red color
You are right. It’s text. I thought the custom format would first convert it to number and then apply the red styling with parenthesis. I guess it’s not the case. How can I convert the entire column to number? I want to do this first, and then run my code - it should work right?
I am afraid, you have use your own code to convert your string data (numbers stored as text) to numeric data for the cells. You may also try to use static .NET methods e.g Convert.ToXXXX() for the purpose.
Thank you.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.