0

所以我想知道我的代码有什么问题,我试图用图像替换文本字段。具体来说,我想用 uncheck.jpg 替换“{no}”,用 check.jpg 替换“{yes}”。我知道我遗漏了一些东西,但我不知道它是什么。当我调试它时,它给出了一个异常 aDoc.InlineShapes.AddPicture("C:\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/check.jpg", ref missing, ref missing, "{yes }"); 类型不匹配。请在短时间内提供帮助。

try
    {
        File.Copy("C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/cover.docx", "C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/temp/" + txtname.Text + " " + txtsur.Text + ".docx", true);
        object missing = Missing.Value;
        Word.Application wordApp = new Word.ApplicationClass();
        Word.Document aDoc = null;
        object filename = "C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/temp/" + txtname.Text + " " + txtsur.Text + ".docx";
        if (File.Exists((string)filename))
        {
            object readOnly = false;
            object isVisible = false;
            wordApp.Visible = false;
            aDoc = wordApp.Documents.Open(ref filename, ref missing,
            ref readOnly, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing,
            ref missing, ref isVisible, ref missing, ref missing,
            ref missing, ref missing);

            aDoc.Activate();
            this.FindAndReplace(wordApp, "{isim}", txtname.Text);
            this.FindAndReplace(wordApp, "{soyisim}", txtsur.Text);

            if (imgbtnyes.ImageUrl == "~/check.jpg" && imgbtnno.ImageUrl == "~/uncheck.jpg")
            {

                aDoc.InlineShapes.AddPicture("C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/check.jpg", ref missing, ref missing, "{yes}");
                aDoc.InlineShapes.AddPicture("C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/uncheck.jpg", ref missing, ref missing, "{no}");
            }
            else if (imgbtnno.ImageUrl == "~/check.jpg" && imgbtnyes.ImageUrl == "~/uncheck.jpg")
            {
                aDoc.InlineShapes.AddPicture("C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/uncheck.jpg", ref missing, ref missing, "{no}");
                aDoc.InlineShapes.AddPicture("C:\\Users/can.KUMSAATI/Documents/Visual Studio 2012/WebSites/WebSite4/check.jpg", ref missing, ref missing, "{yes}");
            }
            else
            {
                Response.Write("<script LANGUAGE='JavaScript'>alert('Seçiniz');</script>");
            }
            aDoc.Save();
            KillProcess(procname);
            if (aDoc.Saved)
            {
                System.Threading.Thread.Sleep(2000);
                Response.ContentType = "Application/msword";
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + txtname.Text + " " + txtsur.Text + ".docx");
                Response.TransmitFile(Server.MapPath("~/temp/" + txtname.Text + " " + txtsur.Text + ".docx"));
                Response.Flush();
                Response.Close();
                Response.End();
            }
        }
        else
            Response.Write("File does not exist.");
        KillProcess(procname);
    }

    catch (Exception)
    {
        Response.Write("Error in process.");
    }
}
private void FindAndReplace(Word.Application wordApp,
        object findText, object replaceText)
{
    object matchCase = true;
    object matchWholeWord = true;
    object matchWildCards = false;
    object matchSoundsLike = false;
    object matchAllWordForms = false;
    object forward = true;
    object format = false;
    object matchKashida = false;
    object matchDiacritics = false;
    object matchAlefHamza = false;
    object matchControl = false;
    object read_only = false;
    object visible = true;
    object replace = 2;
    object wrap = 1;
    wordApp.Selection.Find.Execute(ref findText, ref matchCase,
        ref matchWholeWord, ref matchWildCards, ref matchSoundsLike,
        ref matchAllWordForms, ref forward, ref wrap, ref format,
        ref replaceText, ref replace, ref matchKashida,
                ref matchDiacritics,
        ref matchAlefHamza, ref matchControl);'
4

0 回答 0