Come esportare le equazioni di Excel in altri tipi di espressioni

A volte potrebbe essere necessario esportare le formule di Excel in altri formati nel tuo codice per soddisfare le esigenze del lavoro, quindi la libreria Aspose.Cells può soddisfare le tue esigenze. Il seguente contenuto introduce alcuni metodi su come esportare le formule di Excel in altri formati, spero che questi metodi ti saranno utili.

Abbiamo preparato un esempio di codice qui per aiutarti a raggiungere i tuoi obiettivi usando Aspose.Cells. Sono anche forniti i file di esempio necessari.

File di esempio: Sample.xlsx

Esportare equazioni come espressioni LaTeX

Se vuoi esportare le equazioni di Excel come espressioni LaTeX, puoi usare il metodo ToLaTeX()

Il seguente esempio di codice mostra come usare il metodo ToLaTeX() e inserire i risultati generati in HTML:

C#-To-LaTeX

string dirPath = @"";
Workbook workbook = new Workbook(dirPath + "Sample.xlsx");
StringBuilder sb = new StringBuilder();
sb.Append("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <title>Title</title>\r\n <script type=\"text/javascript\" async src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML\"></script>\r\n <script type=\"text/x-mathjax-config\">\r\n MathJax.Hub.Config({\r\n\t tex2jax: {\r\n\t inlineMath: [['$','$'], ['\\\\(','\\\\)']],\r\n\t processEscapes: true\r\n\t }\r\n\t});\r\n </script>\r\n</head>\r\n<body>");
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
TextBox textBox = (TextBox)shapes[0];
EquationNode mathNode = textBox.GetEquationParagraph().GetChild(0);
string s = mathNode.ToLaTeX();
sb.AppendLine("<p>$" + s + "$</p>");
sb.Append("</body>\r\n</html>");
File.WriteAllText(@"result.html", sb.ToString());

Esportare equazioni come espressioni MathML

Se vuoi esportare le equazioni di Excel come espressioni MathML, puoi usare il metodo ToMathML()

Il seguente esempio di codice mostra come usare il metodo ToMathML() e inserire i risultati generati in HTML:

C#-To-MathML

string dirPath = @"";
Workbook workbook = new Workbook(dirPath + "Sample.xlsx");
StringBuilder sb = new StringBuilder();
sb.Append("<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <title>Title</title>\r\n <script type=\"text/javascript\" async src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML\"></script>\r\n</head>\r\n<body>");
ShapeCollection shapes = workbook.Worksheets[0].Shapes;
TextBox textBox = (TextBox)shapes[0];
EquationNode mathNode = textBox.GetEquationParagraph().GetChild(0);
sb.AppendLine(mathNode.ToMathML());
sb.Append("</body>\r\n</html>");
File.WriteAllText(@"result.html", sb.ToString());