Question

I'm using NPOI to generate XLS spreadsheets. NPOI is an Excel Spreadsheet generation library/API that is available on codeplex, enables you to create workbooks, formatting, formulae and so on and so forth....I use it to create workbooks with multiple sheets that contain the output of the various calculations.

I've used the following custom data format for each cell that contains a value, which I've plumbed into NPOI using code along the lines of:

var newFormat = MyNPOIWorkBook.CreateDataFormat();
var customFormat = newFormat.GetFormat("[=0]0;0.####");

the customFormat is then applied to a Cell within a method that creates the Cell Styles.

This works rather well - but not so well when the 4th decimal place after the point/period is a 0. When this is the case, I do not get the 0. My requirement is to have the 0 actually show!

So, to illustrate. 0.33445566 displays in the spreadsheet as 0.3343 (fine!) - but 0.3340 displays as 0.334 (not fine) - I want 0.3340. I appreciate that this is somewhat trivial, but I would like to satisfy my objective precisely :)

Can anybody help - either by suggesting a workaround, or altering my custom format in some magical fashion?

Thanks -SB

Was it helpful?

Solution

How about [=0]0;0.###0?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top