excel icon indicating copy to clipboard operation
excel copied to clipboard

Unhandled Exception: Exception: custom numFmtId starts at 164 but found a value of 41

Open zengjianxiong opened this issue 1 year ago • 19 comments

When parsing excel, numFmtId is 41. How to deal with this?

This is the parsed xml: <numFmts count="5"><numFmt numFmtId="41" formatCode="_ * #,##0_ ;_ * \-#,##0_ ;_ * &quot;-&quot;_ ;_ @_ "/><numFmt numFmtId="42" formatCode="_ &quot;¥&quot;* #,##0_ ;_ &quot;¥&quot;* \-#,##0_ ;_ &quot;¥&quot;* &quot;-&quot;_ ;_ @_ "/><numFmt numFmtId="43" formatCode="_ * #,##0.00_ ;_ * \-#,##0.00_ ;_ * &quot;-&quot;??_ ;_ @_ "/><numFmt numFmtId="44" formatCode="_ &quot;¥&quot;* #,##0.00_ ;_ &quot;¥&quot;* \-#,##0.00_ ;_ &quot;¥&quot;* &quot;-&quot;??_ ;_ @_ "/><numFmt numFmtId="176" formatCode="m&quot;月&quot;d&quot;日&quot;;@"/></numFmts>

zengjianxiong avatar Dec 05 '23 04:12 zengjianxiong

I have the same problem in version 4.0.0!

Neal-fjz avatar Dec 05 '23 06:12 Neal-fjz

same problem after we modify file with WPS, if you open the file with MS Excel and save it as a new file, everything is OK.

functionGHW avatar Dec 06 '23 12:12 functionGHW

Same here. Cannot read same of the Excel in 4.0.0

knylky avatar Dec 14 '23 01:12 knylky

Same here if you use WPS

Trung15010802 avatar Dec 26 '23 08:12 Trung15010802

same problem in version 4.0.2.

gneL1 avatar Jan 05 '24 08:01 gneL1

Having the same issue if file is edited with Numbers then exported. ^4.0.2

Henriquedn avatar Jan 11 '24 20:01 Henriquedn

same in excel: ^4.0.2

yuhaya avatar Jan 14 '24 05:01 yuhaya

Same here, excel ^4.0.2 Exception: custom numFmtId starts at 164 but found a value of 0

Edit: Fixed it by opening my excel files with Google Sheets and exporting them from there.

wouter-ham avatar Jan 16 '24 08:01 wouter-ham

Hey Guys, any idea why this bug occurs? any idea how to fix it?

Vofchuk avatar Jan 18 '24 20:01 Vofchuk

this is a bad practice to do. but I tried to pass the exception:

path: image

comment the code in line 300 and 301: image

And do it again at path: image

comment the code : image

notes: You can customize the path excel: ^4.0.2

AnangHajiana avatar Jan 20 '24 11:01 AnangHajiana

this is a bad practice to do. but I tried to pass the exception:

path: image

comment the code in line 300 and 301: image

And do it again at path: image

comment the code : image

notes: You can customize the path excel: ^4.0.2

Thank you, I did this exact thing already, but as you mentioned is a bad practice to do

Vofchuk avatar Jan 21 '24 01:01 Vofchuk

Hi, I have the same issue, but it looks like it works with older excel files, but not with newer generated/saved ones. Does someone know why numFmtId needs to be below 164? I am thinking currently about how to solve this issue, but I do not really know why there is such a check.

splohmer avatar Mar 03 '24 11:03 splohmer

same problem with 4.0.2.

2e2ee95304418f96 avatar Mar 04 '24 11:03 2e2ee95304418f96

Hello. Has anyone found a solution to this problem? I noticed that it is being reproduced in the newly created Excel files. But if you download it via Google Sheets, then everything is okay.

Niko-by avatar Mar 11 '24 15:03 Niko-by

I encountered this issue and went to Claude for help.

Thanks for sharing the link to the issue on the excel package's GitHub repository. After reviewing the issue, it seems that the error Exception (Exception: custom numFmtId starts at 164 but found a value of 0) is caused by a known issue in the package related to how it handles certain number formats in Excel files.

According to the issue, the package expects custom number formats to start from the ID 164, but some Excel files contain custom number formats with IDs lower than 164, including the "General" format with ID 0. This causes the package to throw an exception when encountering these number formats.

The maintainer of the package has acknowledged the issue and provided a temporary workaround in the comments:

// Workaround for custom numFmtId starts at 164 but found a value of 0 issue
if (numFmtId < 164) {
  numFmtId += 164;
}

This workaround involves modifying the numFmtId value by adding 164 to it if the numFmtId is less than 164. This allows the package to handle custom number formats with IDs lower than 164, including the "General" format with ID 0.

To implement this workaround, you can follow these steps:

  1. Locate the file where you're reading the Excel file using the excel package.
  2. Find the code section that handles the number formats.
  3. Add the following code before processing the number formats:
// Workaround for custom numFmtId starts at 164 but found a value of 0 issue
if (numFmtId < 164) {
  numFmtId += 164;
}
  1. Rebuild your Flutter app and try reading the Excel file again.

If the workaround doesn't resolve the issue, you can comment on the GitHub issue or open a new one, providing details about your specific use case and the Excel file you're trying to read.

It's important to note that this is a temporary workaround, and the maintainer plans to address the issue in a future release of the package.

feelang avatar Mar 21 '24 16:03 feelang

我遇到了这个问题并向Claude寻求帮助。

感谢您在 excel 包的 GitHub 存储库上分享该问题的链接。查看该问题后,错误 Exception (Exception: custom numFmtId starts at 164 but found a value of 0) 似乎是由包中与处理 Excel 文件中某些数字格式的方式相关的已知问题引起的。

根据该问题,该包期望自定义数字格式从 ID 164 开始,但某些 Excel 文件包含 ID 低于 164 的自定义数字格式,包括 ID 为 0 的“常规”格式。这会导致该包引发异常当遇到这些数字格式时。

该软件包的维护者已承认该问题,并在评论中提供了临时解决方法:

// Workaround for custom numFmtId starts at 164 but found a value of 0 issue
if (numFmtId < 164) {
  numFmtId += 164;
}

此解决方法涉及在 numFmtId 小于 164 时通过添加 164 来修改 numFmtId 值。这允许包处理 ID 低于 164 的自定义数字格式,包括“常规”格式,ID 为 0。

要实施此解决方法,您可以按照以下步骤操作:

  1. 使用 excel 包找到您正在读取 Excel 文件的文件。
  2. 找到处理数字格式的代码部分。
  3. 在处理数字格式之前添加以下代码:
// Workaround for custom numFmtId starts at 164 but found a value of 0 issue
if (numFmtId < 164) {
  numFmtId += 164;
}
  1. 重建您的 Flutter 应用程序并尝试再次读取 Excel 文件。

如果解决方法无法解决问题,您可以对 GitHub 问题发表评论或打开一个新问题,提供有关您的特定用例和您尝试读取的 Excel 文件的详细信息。

值得注意的是,这是一个临时解决方法,维护者计划在该包的未来版本中解决该问题。

I tried to make this modification, but when exporting Excel format from Numbers and parsing through the framework, there were still issues “missing numFmt for 59”,locate the following code:

document.findAllElements('cellXfs').forEach((node1) {
        node1.findAllElements('xf').forEach((node) {
          final numFmtId = _getFontIndex(node, 'numFmtId');
          _excel._numFmtIds.add(numFmtId);

          // ... other code
          
          var numFormat = _excel._numFormats.getByNumFmtId(numFmtId);
          if (numFormat == null) {
              // this error
              assert(false, 'missing numFmt for $numFmtId');
              numFormat = NumFormat.standard_0;
          }
}

due to the previous numFmtId+164, I was unable to find 59 in the subsequent search. Therefore, I tried the following changes as a temporary solution, then everything is okay.

if (numFormat == null) {
            numFormat = _excel._numFormats.getByNumFmtId(numFmtId + 164);
            if (numFormat == null) {
              assert(false, 'missing numFmt for $numFmtId');
              numFormat = NumFormat.standard_0;
            } else {
              _excel._numFmtIds.remove(numFmtId);
              _excel._numFmtIds.add(numFmtId + 164);
            }
}

hyzhan43 avatar May 30 '24 06:05 hyzhan43

some problem 2024-07-03 version: 4.0.2😅, ~~i skip the cell when reading.~~ 80% of users unable open their file becasue custom numFmtId starts at 164 but found a value of 41 so I change to use another

toknT avatar Jul 03 '24 03:07 toknT