如何解决用C#替换Word中图片的文本
| 我正在尝试用我创建的图片替换我的文本(QRCode.png)first method()
{
//creates QRCode
Bitmap b = qCodeEncoder.Encode(encodable);
//saves it
b.Save(\"QrCode.png\",System.Drawing.Imaging.ImageFormat.Png);
FindAndReplace(WordApp,\"<QRCode>\",b);
}
第二种方法是正常的文本替换工具。但是它不能做图像,只能说“ 1”。
private void FindAndReplace(
Microsoft.Office.Interop.Word.Application WordApp,object findText,object replaceWithText)
{
object machtCase = true;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundsLike = false;
object nmachtAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visibible = true;
object replace = 2;
object wrap = 1;
WordApp.Selection.Find.Execute(
ref findText,ref machtCase,ref matchWholeWord,ref matchWildCards,ref matchSoundsLike,ref nmachtAllWordForms,ref forward,ref wrap,ref format,ref replaceWithText,ref replace,ref matchKashida,ref matchDiacritics,ref matchAlefHamza,ref matchControl);
}
解决方法
请看一下OpenXML SDK:
http://msdn.microsoft.com/en-us/library/bb497430.aspx
它不需要安装MS Office,而且速度更快,因为它不会加载应用程序
Word
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。