gpt4 book ai didi

c# - 用C#在Word中用图片替换文本

转载 作者:行者123 更新时间:2023-11-30 18:47:09 24 4
gpt4 key购买 nike

我正在尝试用我创建的图片 (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);
}

第二种方法是正常的文本替代方法。但它不能做图像它只说 System.Drawing.BitMap;

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

关于c# - 用C#在Word中用图片替换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6299961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com