Excel replace image made math equation lost

@mymbrooks,

It seems rendering Math equations in Excel spreadsheets to image format is not supported. Anyways, we need to evaluate it in details.

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): CELLSNET-56180

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.

Hi @mymbrooks
For Aspose.Cells, We did an investigation, We use the following code, can get the following SVG file:

        using (Workbook workbook = new Workbook(path + "Excel.xlsx"))
        {
            ImageOrPrintOptions options = new ImageOrPrintOptions();
            options.ImageType = Aspose.Cells.Drawing.ImageType.Svg;

            foreach (Worksheet worksheet in workbook.Worksheets)
            {
                foreach (Aspose.Cells.Drawing.Shape shape in worksheet.Shapes)
                {
                    // always false
                    if (shape.IsEquation)
                    {
                        index = worksheet.Shapes.IndexOf(shape) + 1;
                        imagePath = Path.Combine(path, "cellsOutput/cells" + index.ToString() + ".svg");
                        shape.ToImage(imagePath, options);
                    }
                }
            }
        }

240712.zip (7.9 KB)

Please describe in detail what you mean by this:

\int_{\theta=0}^{\pi}

You can upload the requirements output as a file attachment as TXT or XML.
So that we can better analyze your needs, thank you.

@leoluo
Test my Test.xlsx, can’t export svg.
I mean is it possible to convert Excel math equation to mathml format like this:


<html>
    <math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mtable columnalign="right left right left right left right left right left" columnspacing="0em" displaystyle="true"><mtr><mtd><mi>V</mi><mo stretchy="false">(</mo><mi>R</mi><mo stretchy="false">)</mo></mtd><mtd><mo>=</mo><msubsup><mo>∫</mo><mrow><mi>φ</mi><mo>=</mo><mn>0</mn></mrow><mrow><mn>2</mn><mi>π</mi></mrow></msubsup><msubsup><mo>∫</mo><mrow><mi>θ</mi><mo>=</mo><mn>0</mn></mrow><mi>π</mi></msubsup><msubsup><mo>∫</mo><mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow><mi>R</mi></msubsup><msup><mi>r</mi><mn>2</mn></msup><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mi>d</mi><mi>r</mi><mi>d</mi><mi>θ</mi><mi>d</mi><mi>φ</mi></mtd></mtr><mtr><mtd></mtd><mtd><mo>=</mo><mrow><mo>(</mo><mrow><msubsup><mo>∫</mo><mrow><mi>φ</mi><mo>=</mo><mn>0</mn></mrow><mrow><mn>2</mn><mi>π</mi></mrow></msubsup><mi>d</mi><mi>φ</mi></mrow><mo>)</mo></mrow><mrow><mo>(</mo><mrow><msubsup><mo>∫</mo><mrow><mi>θ</mi><mo>=</mo><mn>0</mn></mrow><mi>π</mi></msubsup><mo lspace="0em" rspace="0em">sin</mo><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mi>d</mi><mi>θ</mi></mrow><mo>)</mo></mrow><mrow><mo>(</mo><mrow><msubsup><mo>∫</mo><mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow><mi>R</mi></msubsup><msup><mi>r</mi><mn>2</mn></msup><mi>d</mi><mi>r</mi></mrow><mo>)</mo></mrow></mtd></mtr><mtr><mtd></mtd><mtd><mo>=</mo><msubsup><mrow><mo>[</mo><mi>φ</mi><mo>]</mo></mrow><mrow><mi>φ</mi><mo>=</mo><mn>0</mn></mrow><mrow><mn>2</mn><mi>π</mi></mrow></msubsup><msubsup><mrow><mo>[</mo><mrow><mo>−</mo><mo lspace="0em" rspace="0em">cos</mo><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><mo>]</mo></mrow><mrow><mi>θ</mi><mo>=</mo><mn>0</mn></mrow><mi>π</mi></msubsup><msubsup><mrow><mo>[</mo><mfrac><msup><mi>r</mi><mn>3</mn></msup><mn>3</mn></mfrac><mo>]</mo></mrow><mrow><mi>r</mi><mo>=</mo><mn>0</mn></mrow><mi>R</mi></msubsup></mtd></mtr><mtr><mtd></mtd><mtd><mo>=</mo><mfrac><mn>4</mn><mn>3</mn></mfrac><mi>π</mi><msup><mi>R</mi><mn>3</mn></msup></mtd></mtr></mtable><annotation encoding="TeX">
      \begin{aligned}
      V(R) &amp;=
      \int_{\varphi=0}^{2 \pi}
      \int_{\theta=0}^{\pi}
      \int_{r=0}^{R}
      r^2 \sin(\theta) dr d\theta d\varphi \\ &amp;=
      \left( \int_{\varphi=0}^{2 \pi}  d\varphi \right)
      \left( \int_{\theta=0}^{\pi} \sin(\theta)  d\theta \right)
      \left( \int_{r=0}^{R} r^2 dr \right) \\ &amp;=
      \left[   \varphi \right]_{\varphi=0}^{2 \pi}
      \left[  -\cos(\theta) \right]_{\theta=0}^{\pi}
      \left[ \frac{r^3}{3} \right]_{r=0}^{R} \\ &amp;=
      \frac{4}{3} \pi R^3
      \end{aligned}
    </annotation></semantics></math>
</html>

Sample file
Test2.zip (14.0 KB)

@mymbrooks
1). We have fixed the issue of reading equations from your template file.
2).

Which tool created this html?
“\int_{\theta=0}^{\pi}” is the annotation part in your attached html, the format is “TeX” ,not MathML. So is “Tex” your expected format?

Both MathML and Text are new file format for us. And they are different from “http://schemas.openxmlformats.org/officeDocument/2006/math” (office math).
We have to check whether we should support them first.

Now you can get EquationNode with the following codes:

TextBox textBox = workbook.Worksheets[0].TextBoxes[0];
EquationNode node = textBox.GetEquationParagraph();

Sorry for my mistake. Yes, It’s Tex and difference from mathml.
Because modern browsers support Text、mathml, so I ask for this feature for some customer requirement.

@mymbrooks,

Thanks for your feedback and confirmation.

We will investigate if we could support rendering math equation to TeX format. 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): CELLSNET-56213

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.

@mymbrooks
Did you want to directly extract equation to a TeX String or Embed the equation into html as a TeX string (now Aspose.Cells exports an image)?
1). We plan to add EquationNode.ToTeX() method to directly extract equation to a Tex String:

TextBox textBox = workbook.Worksheets[0].TextBoxes[0];
EquationNode node = textBox.GetEquationParagraph();
node.ToTeX();

2). If exporting TeX to html, the most common and user-friendly methods are using MathJax or KaTeX to make the TeX work. So if exporting to html, would you like to add those external JS references?

@simon.zhao
Thanks for quick solution.
No need to export HTML, just Tex string.
I will show it with front framework(Vue etc…)

@mymbrooks
Thanks for your confirm.
We will start to support EquationNode.ToTeX(); first.
And it’s better that you can share files contains your excepted equations. We will prioritize implementing the ones you frequently use because there are two many TeX Equation syntax.

@simon.zhao
Take it easy, this feature is in my wish list, not for production now.
I want to serialization math equation in my work.
I will share some example equation
Example.zip (75.5 KB)

@mymbrooks,

Thank you for providing your desired TeX equations. We have logged the archive with your existing ticket “CELLSNET-56213” into our database. We will look into the equations list soon.

@mymbrooks,

We are pleased to inform you that your issue (Ticket ID: “CELLSNET-56177”) has been resolved now. The fix will be included in the upcoming release (Aspose.Cells v24.8) which we plan to release in the first half of August 2024. We will notify you when the next release is released.

@mymbrooks
tab2.zip (175 Bytes)

Please check the attached file with the equation in your test.xlsx.

The first character is Mathematical Italic Capital X ( UTF-16 Encoding: `0xD835 0xDC4B’).

@mymbrooks
After closely comparing LaTeX and Tex syntax, we decided to add EquationNode.ToLaTeX(); not ToTex().
Sorry for confusion in the previous post.

@simon.zhao
Thanks it’s OK, support for LaTeX is enough and LaTeX is widely used too.

@mymbrooks
Thank you for your feedback. You are welcome. Once there are any updates, we will notify you promptly.

The issues you have found earlier (filed as CELLSNET-56177) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

@mymbrooks
Your issues (CELLSNET-56180 and CELLSNET-56213) have been resolved and the fixed functionality will be released with version 24.9. We have add two API interfaces: ToLaTeX() and ToMathML() to facilitate your work. Currently, we provide export functions for most common formulas. If you encounter any problems during the export process, please feel free to contact us.

@duojie.yang Thanks, good job I will try later.

@mymbrooks
You are welcome!