1

Как можно заменить текст на изображение? Пытаюсь через буфер обмена-простое место вместо текста.

Clipboard.SetImage(Image.FromFile("E:\\Dropbox\\Фонд\\1310\\опрос\\1210\\Statistick_program\\Statistick_program\\bin\\Debug\\dig1.bmp"));
    // copy the image to the clipboard

  //  Clipboard.SetImage("^E:\\Dropbox\\Фонд\\1310\\опрос\\1210\\Statistick_program\\Statistick_program\\bin\\Debug\\dig1.bmp");

    app.Selection.Find.Execute(FindText: "<dig1>", ReplaceWith: Clipboard.GetImage());

    object SaveASFile = (object)Directory.GetCurrentDirectory() + "\\Temp57.doc";
    doc.SaveAs(SaveASFile, missing, missing, missing, missing);
    doc.Close(false, missing, missing);

1 ответ 1

0

А вот и ответ:

   var app = new Application();
        try {
            //This code creates a document based on the specified template.
            var doc = app.Documents.Add(
                Path.GetFullPath(@"Docs\foo.dotx"),
                Visible: false);

            doc.Activate();

            //for each keyword you want to replace.
            //************************************************
            var keyword = "angus-young";
            Console.WriteLine("Replacing keyword: {0} ...",keyword);
            var sel = app.Selection;                
            sel.Find.Text = string.Format("[{0}]", keyword);                
            sel.Find.Execute(Replace: WdReplace.wdReplaceNone);
            sel.Range.Select();                

            //This code inserts the image
            var imgPath = Path.GetFullPath(string.Format(@"Img\{0}.jpg", keyword));
            sel.InlineShapes.AddPicture(
                FileName: imgPath,
                LinkToFile: false,
                SaveWithDocument: true);
            //************************************************

            //finally, save the doc.
            doc.SaveAs(Path.GetFullPath(@"Docs\foo.docx"));
            doc.Close();
        }
        catch (Exception ex) {
            Console.WriteLine(ex.Message);
        }
        finally {                
            app.Quit();
            sys.Runtime.InteropServices.Marshal.FinalReleaseComObject(app);                
        }
        Console.WriteLine("Press [Enter] to exit");

Console.ReadLine();

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.