Load converted SpreadsheetML: Invalid column index

Steps to reproduce:

  1. Create a new Excel file.
  2. Select columns after e.g. M until the last one.
  3. Right-click on column names and select Hide.
  4. Keep clicking on a right arrow of a horizontal scroll bar until no column is visible.
  5. Save file.
  6. Convert the file to SpreadsheetML via Aspose - new Workbook(input).save(output, SaveFormat.SPREADSHEET_ML). It succeed but note that <WorksheetOptions> contains <LeftColumnVisible>-1</LeftColumnVisible>.
  7. Load the SpreadsheetML file via Workbook.

Current behavior:

com.aspose.cells.CellsException: Invalid column index.
at com.aspose.cells.x4e.c(Unknown Source)
at com.aspose.cells.Worksheet.setFirstVisibleColumn(Unknown Source)
at com.aspose.cells.b9n.a(Unknown Source)
at com.aspose.cells.b9n.j(Unknown Source)
at com.aspose.cells.b9n.a(Unknown Source)
at com.aspose.cells.b9n.a(Unknown Source)
at com.aspose.cells.u7k.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.<init>(Unknown Source)

Notes:

  • Input and converted files: files.7z (6.8 KB)
  • I use Aspose.Cells for Java v25.11.

@tomasbelusky

Summary
When a worksheet has all columns hidden, Aspose.Cells v25.11 writes <LeftColumnVisible>-1</LeftColumnVisible> into the SpreadsheetML. During loading the SDK tries to set the first visible column to ‑1, which is outside the valid range (0 – maxColumn) and throws a CellsException: Invalid column index.

Why it happens

  • LeftColumnVisible tells Excel which column should be the first visible one when the sheet opens.
  • Valid values are 0 to the index of the last column. ‑1 is not a legal column index.
  • In version 25.11 the writer does not clamp this value when the sheet ends up with no visible columns, so the generated XML contains -1.
  • When the XML is parsed, the SDK calls Worksheet.setFirstVisibleColumn(-1), which raises the exception.

What to do next

  1. Upgrade Aspose.Cells (if possible) – This behaviour has been reported as a bug in 25.11. Later releases contain a fix that prevents -1 from being written. Updating to the newest available version is the simplest way to avoid the problem.
  2. Edit the SpreadsheetML before loading (a manual workaround when you must stay on 25.11)
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

// Load the XML
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new FileInputStream("converted.xml"));

// Replace any <LeftColumnVisible>-1</LeftColumnVisible> with 0 (or remove the element)
NodeList list = doc.getElementsByTagName("LeftColumnVisible");
for (int i = 0; i < list.getLength(); i++) {
Element el = (Element) list.item(i);
if ("-1".equals(el.getTextContent())) {
el.setTextContent("0"); // or el.getParentNode().removeChild(el);
}
}

// Write the corrected XML to a stream
Transformer transformer = TransformerFactory.newInstance().newTransformer();
ByteArrayOutputStream corrected = new ByteArrayOutputStream();
transformer.transform(new DOMSource(doc), new StreamResult(corrected));

// Load the corrected XML
Workbook wb = new Workbook(new ByteArrayInputStream(corrected.toByteArray()));
  1. Prevent the situation when creating the source workbook – If you can control the original Excel file, keep at least one column visible before saving to SpreadsheetML (e.g., hide columns N‑Z but leave A‑M visible). This stops the writer from emitting -1.
  2. Contact Aspose Support – If upgrading is not an option or the issue persists in newer versions, open a support ticket and provide the sample files. The Aspose team can confirm whether the bug is fixed in a specific build or supply an official workaround.

Note: The LoadOptions.setIgnoreInvalidData(true) method mentioned in some community posts does not exist in the Aspose.Cells Java API, so it cannot be used as a workaround.


Please verify the behaviour with the exact version you are using and, if possible, test the upgrade path before applying any changes to production code.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

SDK version unclear — refer to the official release notes before applying this guidance.

@tomasbelusky,

Thanks for the sample files and details.

I reproduced the issue as you mentioned by using your input Excel file and following sample code. I found loading the converted SpreadsheetML file causes an exception “Invalid column index”.

new Workbook("d:\\files\\input.xlsx").save("d:\\files\\converted.xml", SaveFormat.SPREADSHEET_ML);
new Workbook("d:\\files\\converted.xml",new LoadOptions(LoadFormat.SPREADSHEET_ML));//exception

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46559

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.