Autor Beitrag
Vegeto
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 262



BeitragVerfasst: Mi 20.02.13 16:28 
Hallo,

ist es möglich Bilder, die man auswählt, mittels Interop in eine Word Datei einzufügen, ich spreche hier von Formaten wie .jpg, .gif(nicht animiert)und .png.

Ist so etwas möglich, wenn man die Felder in C# anspricht und sie dann einfügt und ihre Größe im Programm anpassen kann?

Ich freue mich für jeden Link, jede Anregung oder jede Hilfestellung.

Bis dahin mit freundlichen Grüßen
Vegeto
Christoph1972
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: Mi 20.02.13 17:47 
Hi,

in einem Projekt habe ich das so gemacht:

Ein Word-Vorlage erstellt, mit einem Frame, jedes Element im Word hat ein Index (keine Ahnung mehr ob man den selbst vergeben muss, oder ob das automatisch passiert!?, ist zu lange her.)
Das Image temp zwischengespeichert.

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
public void ShowWordReport(string id, string image, string wordPatternFile)
{
    if (!File.Exists(wordPatternFile))
    {
        MessageBox.Show("Die Vorlage wurde nicht gefunden!""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    ApplicationClass myWordApp = new ApplicationClass();

    myWordApp.Visible = true;

    object wordPattern = wordPatternFile;
    object newDoc = false;
    object documentType = 0;
    object visible = true;

    Document aDoc = myWordApp.Documents.Add(ref wordPattern, ref newDoc, ref documentType, ref visible);

    object n = Type.Missing;
    
    //Bezeichnung einfügen
    //---------------------------------------------------------
    object index = 3;
    object what = WdGoToItem.wdGoToBookmark;
    object name = aDoc.Bookmarks.get_Item(ref index).Name;
    myWordApp.Selection.GoTo(ref what, ref n, ref n, ref name);
    myWordApp.Selection.Text = id;
    //---------------------------------------------------------
    
    //Image einfügen
    //--------------------------------------------------------- 
    object indexTextBox1 = 1;
    Shape molMassTextBox = aDoc.Shapes.get_Item(ref indexTextBox1);
    molMassTextBox.Fill.UserPicture(image);
    //--------------------------------------------------------- 
}


Ich denke das solte dir weiterhelfen :-) Google kennt sicher noch mehr......

_________________
Gruß
Christoph

Für diesen Beitrag haben gedankt: Vegeto
Vegeto Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 262



BeitragVerfasst: Do 21.02.13 09:28 
Hallo Christoph1972

Danke für deine Antwort :)
Ich werde mich daran setzen und versuchen ein Bild einzufügen, also ich arbeite nicht mit Booksmarks, sondern mit Mergefields, die werden anders angesprochen, aber der Vorgang den du mir gegeben hast, müsste auch auf Mergefields Funktionieren.

Ich bedanke mich, falls fragen am Code auftauchen melde ich mich.

Lg
Vegeto Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 262



BeitragVerfasst: Do 21.02.13 10:26 
Hallo

TUT MIR LEID, aber ich habe es nicht geschafft :(
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
if (f.Code.Text == " MERGEFIELD Pictures ")
                        {
                            f.Select(); // f beschreibt das Mergefield
                            myDoc.InlineShapes.AddPicture(Bildpath);
                        }


so sieht der zweig aus, doch der fügt das Bild einfach willkürlich in die Datei ein, nicht an der Select stelle.

Kann mir eventuell jmd weiterhelfen?

Lg