When there is a mathtype formula in the word document, if you delete the picture in the document and save it and then open it and double-click the formula, you can’t edit it, this should be all the names of the pictures changed after saving, resulting in wmf and ole association errors, so you can’t open the formula
2024年8月26日小学数学作业 (12)(2).docx (2.7 MB)
@xhuigy Could you please attach your input document and code that will allow us to reproduce the problem? As I can see the document attached above is the output document produced by Aspose.Words.
Found the problem it’s not deletion, it’s setting the name to the wmf: shape.Name="new name”
var shapes = doc.GetChildNodes(word.NodeType.Shape, true);
foreach (word.Drawing.Shape shape in shapes)
{
shape.Name="new name";
}
@xhuigy Unfortunately, I cannot reproduce the problem. In both, input and output, documents, when I double click on the equations in your document I see the following message:
If I click Yes
, the equation is succesfuly converted to OfficeMath and can be edited.
Document doc = new Document(fileName);
var pnum = 0;
// 创建一个列表存储PNG图片
List<Shape> pngImages = new List<Shape>();
int count = 0;
int cttt = 0;
// 遍历文档中的所有形状
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
shape.ImageData.Title = "";
//图像数据的源文件的完全路径。
shape.ImageData.SourceFullName = "";
shape.BehindText = false;
//图片不显示,代替显示的文字
shape.AlternativeText = "";
shape.Title = "";
//获取或设置当鼠标悬停在形状上时显示的屏幕提示文本。
shape.ScreenTip = "";
//获取或设置形状的超链接。当点击这个形状时,就会打开这个超链接。
shape.HRef = "";
shape.Target = "";
if (!shape.HasImage) continue;
// 检查形状是否包含图像
//if (shape.OleFormat == null || !shape.OleFormat.ProgId.StartsWith("Equation"))
//{
shape.Name = string.Format("pic{0}.xxxx.com", pnum);
//}
if (shape.HasImage)
{
// 获取图像格式
string imageFormat = shape.ImageData.ImageType.ToString();
// 如果图像格式是PNG,添加到列表中
if (imageFormat.Equals("Png", StringComparison.OrdinalIgnoreCase))
{
pngImages.Add(shape);
if (count == 0)
{
shape.Remove();
// break;
}
}
count++;
}
}
// 保存为新的docx文件
string newFileName = "new-document-without-png.docx";
doc.Save(newFileName);
@xhuigy Thank you for additional information. The problem occurs because you are setting the same shape name for each shape. In your code pnum
variable is not incremented. Please modify code like this:
shape.Name = string.Format("pic{0}.xxxx.com", pnum++);