Count numberformats?

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
d3nton
Posts: 137
Joined: Thu Oct 25, 2012 9:48 am

Count numberformats?

Post by d3nton »

Hi!
To apply a specific formatting to an excel cell i use e.g

Code: Select all

  
  self.CmdFormat.BeginEdit(psheet);
  self.CmdFormat.Number.Format := pNumberFormat;
  self.CmdFormat.Apply(pColumn, pRow);
It seems that there is a limitation of different formats for an excel file (or maybe a single excel sheet, i'm not sure). Adding more formats will result in a corrupted excel file.
The limit seems to be 200 or maybe 255, i'm not sure.
Is there a way to count the used number of formats in an excel file?
If I extract an xlsx file and take alook in xl/style.xml is see something like:
<numFmts count="120" >
<numFmt numFmtId="50" formatCode="0.0" Mosa.doc"" />
<numFmt numFmtId="51" formatCode="0.0" Dravima.doc"" />
<numFmt numFmtId="52" formatCode="0.0" Jongstra.doc"" />
<numFmt numFmtId="53" formatCode="0.0" .xls"" />
<numFmt numFmtId="54" formatCode="0.0" Pallets.xls"" />
<numFmt numFmtId="55" formatCode="0.0" ziekteverzuimbegeleidingsformulier.doc"" />
<numFmt numFmtId="56" formatCode="0.0" overwerkdeclaratie.doc"" />
....
Is there a property in xlsReadWrite to query these value so that I am able to prevent creating a corrupt excel file by querying these value and stop adding new numberformats in case that a specific limit is reached?.
I also wonder why the first numFmtId starts with '50'and not '0'.

Thank you.
d3nton
Posts: 137
Joined: Thu Oct 25, 2012 9:48 am

Re: Count numberformats?

Post by d3nton »

Okay. I found the property :-)
xlsfile.Manager.StyleSheet.NumFmts.Count can be used to check if a new format can be added:

Code: Select all

if (xlsfile.Manager.StyleSheet.NumFmts.Count < 256) then begin
  xlsfile.CmdFormat.BeginEdit(psheet);
  xlsfile.CmdFormat.Number.Format := pNumberFormat;
  xlsfile.CmdFormat.Apply(pColumn, pRow);
end;
best regards d3nton
Post Reply