简体   繁体   中英

Replace a text in Word doc with a picture from a database c#

I know how to get a picture from a databse as Byte array :

string query2 = "SELECT Logo FROM Client WHERE CompanyName = '"+CN+"' ;";
using (SqlCeCommand command1 = new SqlCeCommand(query2, connection))
{
    try
    {
        SqlCeDataReader reader3 = command1.ExecuteReader();
        while (reader3.Read())
        {
            byte[] byteArray = (byte[])reader3["Logo"];
            Image img = byteArrayToImage(byteArray);
        }
    }
    catch (Exception excf)
    {
        MessageBox.Show(excf.Message);
    }
}

I know how to replace some text by an image using the image's path :

var kword = "#Logo#";
var sel = app.Selection;
sel.Find.Text = kword;
sel.Find.Execute(Replace: WdReplace.wdReplaceOne);
sel.Range.Select();
sel.InlineShapes.AddPicture(imagePath);

But I don't know (and I realy can't figure out how to replace some text by the image I got in my database.

I'm sure there is something obvious that I'm missing but I didn't find the answer on google.

Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM