webForumDet fria alternativet

Interop.Word

3 svar · 470 visningar · startad av Zaiman

ZaimanMedlem sedan dec. 20014 239 inlägg
#1

Hej.
Har stött på patrull. Ska göra lite etiketter i word hade jag tänkt mig.
Men bilden som jag placerar ut kommer endast på den första och sista sidan.
Fast på den första sidan många gånger.
Har inte jobbat med detta tidigare och behöver lite hjälp. Hur får jag bilden placerad på varje sida?

            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc";
            object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;

            Microsoft.Office.Interop.Word.Application oWord;
            Microsoft.Office.Interop.Word.Document oDoc;
            Microsoft.Office.Interop.Word.Range wRange;
            oWord = new Microsoft.Office.Interop.Word.Application();
            oWord.Visible = true;

            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            oDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperCustom;
            oDoc.PageSetup.RightMargin = 0;
            oDoc.PageSetup.LeftMargin = 0;
            oDoc.PageSetup.TopMargin = 0;
            oDoc.PageSetup.BottomMargin = 0;
            float _pageWidth = 215.5f;
            float _pageHeight = 87.9f;
            oDoc.PageSetup.PageWidth = _pageWidth;
            oDoc.PageSetup.PageHeight = _pageHeight;
            wRange = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            int i = 10;
            while (i > 1)
            {
                
                oDoc.Shapes.AddPicture(@"C:\Pictures\ek1.gif", ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                wRange.InsertBreak(ref oPageBreak);
                i--;
            }

Försökte hitta något vettigt men vet inte riktigt vad jag ska söka efter.

/r
Det jag vill åstadkomma är alltså en bild per sida i dokumentet.

PMedlem sedan jan. 20012 204 inlägg
#2

Interop.word / excel är ju inte direkt roliga att arbeta med.
http://www.codeproject.com/KB/vb/dotNETComponentCOMClient.aspx
Där gör de något med page-break i alla fall, men det är kanske inte det som är problemet. Bilden kanske måste formateras så att de inte hamnar på varandra?

ZaimanMedlem sedan dec. 20014 239 inlägg
#3

Hmm var inne på samma linje, men får det inte att fungera.
Får ett null pointer exception.

ZaimanMedlem sedan dec. 20014 239 inlägg
#4

Så nu kommer det en bild på varje sida :)
Bara för mig att börja sy in det i den gamla koden och få till placeringen. En bit på väg iaf.

 {
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc";
            object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            object oPage = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;

            Microsoft.Office.Interop.Word.Application oWord;
            Microsoft.Office.Interop.Word.Document oDoc;
            Microsoft.Office.Interop.Word.Range wRange;
            Microsoft.Office.Interop.Word.Selection oSel;
            oWord = new Microsoft.Office.Interop.Word.Application();
            oWord.Visible = true;

            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            oDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperCustom;
            oDoc.PageSetup.RightMargin = 0;
            oDoc.PageSetup.LeftMargin = 0;
            oDoc.PageSetup.TopMargin = 0;
            oDoc.PageSetup.BottomMargin = 0;
            float _pageWidth = 215.5f;
            float _pageHeight = 87.9f;
            oDoc.PageSetup.PageWidth = _pageWidth;
            oDoc.PageSetup.PageHeight = _pageHeight;
            wRange = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            oSel = oWord.Selection;

            int i = 10;
            while (i > 1)
            {
                oSel.InlineShapes.AddPicture(@"C:\Pictures\ek1.gif", ref oMissing, ref oMissing, ref oMissing);
                oSel.InsertBreak(ref oPageBreak);
                i--;
            }
            wRange = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
         
            object oSave = false;
            // oDoc.Close(ref oSave, ref oMissing, ref oMissing);
        }
122 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
119 ms — hämta tråd, inlägg och bilagor (db)