Aspose.Cells 无法正常加载camera shape

当drawing.xml的a14:cameraTool节点没有spid属性的时候,aspose.cells将会无法正常解析camera shape的CellRange,导致camera shape的内容丢失。附件为测试文件
image.png (13.3 KB)
image.png (9.5 KB)

camera shape.zip (8.3 KB)

@ChenGY1234

Solution Overview

The camera shape is stored in the drawing part of the XLSX file as an <a14:cameraTool> element.
If the element does not contain the required spid (shape‑ID) attribute, Aspose.Cells cannot map the camera to a cell range, so the shape is ignored during loading/rendering.

Below are the recommended actions:

Action When to use
Upgrade to the latest Aspose.Cells (≥ 24.9) You are on an older version. The issue is fixed in 24.9 – the parser now generates a temporary spid when it is missing.
Patch the file manually You must keep the current version (e.g., a production lock‑down) and need an immediate workaround.
Re‑create the camera shape after loading You cannot modify the original file (e.g., the file is read‑only) and only need the visual representation.

:one: Upgrade (Preferred)

# NuGet (C#)
Install-Package Aspose.Cells -Version 24.10.0   # or the newest available version

After upgrading, the same code you already use to open the workbook will correctly render the camera shape.


:two: Temporary Work‑around – Patch the XLSX before loading

  1. Extract the XLSX (it is a ZIP archive).
  2. Locate the drawing file, e.g. xl/drawings/drawing1.xml.
  3. Add a unique spid attribute to every <a14:cameraTool> element that lacks it.
  4. Re‑zip the folder back to an XLSX and load it with Aspose.Cells.

C# helper script

using System;
using System.IO;
using System.IO.Compression;
using System.Xml.Linq;

class CameraShapePatcher
{
    static void Main()
    {
        string sourceXlsx = @"C:\Temp\CameraShape.xlsx";
        string tempDir    = Path.Combine(Path.GetTempPath(), "xlsx_patch");
        string outXlsx    = @"C:\Temp\CameraShape_fixed.xlsx";

        // 1. Unzip
        if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
        ZipFile.ExtractToDirectory(sourceXlsx, tempDir);

        // 2. Find drawing XML files
        var drawingFiles = Directory.GetFiles(
            Path.Combine(tempDir, "xl", "drawings"),
            "*.xml",
            SearchOption.TopDirectoryOnly);

        XNamespace a14 = "http://schemas.microsoft.com/office/drawing/2010/main";

        foreach (var file in drawingFiles)
        {
            var doc = XDocument.Load(file);
            bool changed = false;

            foreach (var cam in doc.Descendants(a14 + "cameraTool"))
            {
                if (cam.Attribute("spid") == null)
                {
                    cam.SetAttributeValue("spid",
                        "spid_" + Guid.NewGuid().ToString("N"));
                    changed = true;
                }
            }

            if (changed) doc.Save(file);
        }

        // 3. Re‑zip
        if (File.Exists(outXlsx)) File.Delete(outXlsx);
        ZipFile.CreateFromDirectory(tempDir, outXlsx);

        // 4. Load with Aspose.Cells to verify
        var wb = new Aspose.Cells.Workbook(outXlsx);
        Console.WriteLine("Workbook loaded successfully.");
    }
}

Notes

  • The script works on a single machine; in production you should add error handling and integrity checks (e.g., hash verification).
  • Only the spid attribute is added – no other parts of the file are altered.

:three: Re‑create the camera shape after loading (no file modification)

If you cannot touch the original file, you can load the workbook, delete any broken camera shape, and insert a picture that mimics the camera’s visual output. Aspose.Cells does not expose a dedicated AddCamera method, but a picture can be used as a functional replacement.

using Aspose.Cells;
using System.Drawing;   // for Image

// 1. Load the workbook (any version)
var wb = new Workbook(@"C:\Temp\CameraShape.xlsx");
var ws = wb.Worksheets[0];

// 2. Remove any existing (broken) camera shapes
for (int i = ws.Shapes.Count - 1; i >= 0; i--)
{
    var shape = ws.Shapes[i];
    if (shape.Type == ShapeType.Picture && shape.Name.StartsWith("Camera"))
        shape.Delete();
}

// 3. Create a picture that represents the camera view
//    (You need an image file that you want to show – e.g., a snapshot of the range)
string imagePath = @"C:\Temp\RangeSnapshot.png";
int firstRow = 0, firstColumn = 0, lastRow = 4, lastColumn = 3;

// Add the picture and position it over the target range
var picture = ws.Pictures.Add(firstRow, firstColumn, lastRow, lastColumn, imagePath);
picture.Name = "Camera1";

// 4. Save the workbook
wb.Save(@"C:\Temp\CameraShape_fixed.xlsx");

What you lose – The original camera shape stores a live link to a cell range, so changes in the range are reflected automatically. The picture approach is static; you must regenerate the image if the source data changes.


:four: Quick Checklist for the Caller

  1. Check versionConsole.WriteLine(Aspose.Cells.Version);
    If < 24.9 → upgrade or apply a workaround.
  2. Inspect the XML – Open the XLSX with any zip tool and verify that every <a14:cameraTool> has an spid.
  3. Apply the patch (Section 2) or re‑create the shape (Section 3).
  4. Retest – Load the workbook with Aspose.Cells and confirm the camera (or picture) appears.
  5. If the problem persists, provide:
    • Aspose.Cells version string,
    • The exact exception message / stack trace (if any),
    • A minimal reproducible XLSX (with confidential data removed).

:five: Closing

Upgrading to the latest Aspose.Cells version is the cleanest solution because the library now handles missing spid attributes internally. The two work‑arounds above let you keep the current version while still being able to open or display the file.

Feel free to reach out with the requested details if you need further assistance. Happy coding!

@ChenGY1234,

感谢提供模板Excel文件和截图。

经过初步测试,我使用您的模板Excel文件和以下示例代码片段,成功复现了该问题。我发现Aspose.Cells无法正确解析摄像机形状的CellRange,导致输出Excel文件中摄像机形状的内容丢失。

var wb = new Workbook("e:\\test2\\camera shape.xlsx");
wb.Save("e:\\test2\\out1.xlsx");

我们需要对该问题进行彻底评估。我们已在内部问题追踪系统中创建了以下新工单,并将根据免费支持政策中提到的条款提供修复。

问题编号:CELLSNET-59291

您可以通过付费支持服务获得优先支持,同时直接联系我们的付费支持管理团队。

@ChenGY1234,

我们在此通知您,您的问题(工单编号:“CELLSNET-59291”)已解决。此修复/增强功能将包含在下一个版本(Aspose.Cells v25.11)中,预计于2025年11月初发布(大约在10日至15日之间)。一旦新版本可用,我们将再次与您联系。