Open XML SDK 2.5除錯流程:以列索引值的起始值超出範圍為例

  • 491
  • 0

Open XML SDK 2.5除錯流程:以列索引值的起始值超出範圍為例

使用Open XML SDK修改xlsx檔案之後,利用Excel 2013開啟檔案,出現下列措誤訊息:

We found a problem with some content in '檔名.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.

 

倘若放棄修正錯誤,檔案將會自動關閉。

 

倘若接受修正錯誤,將會出現下列錯誤訊息:

Excel was able to open the file by repairing or removing the unreadable content.

Removed Records: Cell information from /xl/worksheets/sheet1.xml part

 

接著依據提示打開位於C:\Users\{使用者名稱}\AppData\Local\Temp\error{檔名}.xml檔案,發現錯誤訊息大致與前述的訊息一致。

由於前述訊息不足以協助找出問題原因,

於是使用Open XML SDK 2.5 Productivity Tool開啟被修改的xlsx檔案,並且點選Validate。

接著出現下列措誤訊息:

There are totally 1 errors in the package "檔名.xlsx". Below is the detail information:
Error Node Type        Row
Error Part                  /xl/worksheets/sheet1.xml
Error Node Path         /x:worksheet[1]/x:sheetData[1]/x:row[10146]
Related Node Type
Related Part
Description                The attribute 'r' has invalid value '0'. The MinInclusive constraint failed. The value must be greater than or equal to 1.

 

解決方式:將列索引值由零起跳改為由一起跳。