Aspose Word .Net能否实现拿一份标准格式的word文档,比如说投标文件什么的,根据标题来识别。
通过C#代码识别文字、图片,然后导入数据库,里面有可能是文字或图片,超链接
我们要通过代码判断然后进行操作
@Zyw,
要获取或设置Word文档的标题,请使用以下代码:
Document doc = new Document("E:\\Temp\\Input.docx");
Console.WriteLine(doc.BuiltInDocumentProperties.Title);
您可以遍历Paragraph集合以识别Word文档中的某些文本,然后将Paragraph(HTML表示)存储在数据库中。
Document doc = new Document("E:\\Temp\\Input.docx");
Paragraph targetPara = null;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
if (para.ToString(SaveFormat.Text).Contains("Some Text"))
{
targetPara = para;
}
}
if (targetPara != null)
{
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.ExportImagesAsBase64 = true;
opts.CssStyleSheetType = CssStyleSheetType.Inline;
string htmlString = targetPara.ToString(opts);
}
您还可以通过其ALT文本确定Word文档中的图片。
Document doc = new Document("E:\\Temp\\Input.doc");
Shape targetPicture = null;
foreach (Shape img in doc.GetChildNodes(NodeType.Shape, true))
{
if (img.HasImage && img.AlternativeText == "SOME ALT TEXT")
{
targetPicture = img;
}
}
if (targetPicture != null)
{
// do something
}
您还可以使用以下C#.NET代码在Word文档中检测超链接。
Document doc = new Document("E:\\Temp\\SampleMergeField\\Input.doc");
ArrayList hyperlinks = new ArrayList();
foreach (Field field in doc.Range.Fields)
{
if (field.Type == Aspose.Words.Fields.FieldType.FieldHyperlink)
{
FieldHyperlink hyperlink = (FieldHyperlink)field;
hyperlinks.Add(hyperlink);
}
}