Привет! Вот кусок кода для работы MSWord как с COM может это тебе чем-то поможет здесь я скидываю информацию из DataSet в таблицу MSWord с ее дальнейшем форматированием пример правда на C#. но различия небольшие в части работы с COM namespace test { using System; using Data = System.Data; using SQL = System.Data.SqlClient; using Reflection = System.Reflection; // For Missing.Value and BindingFlags using Interop = System.Runtime.InteropServices; // For COMException using ArrayList = System.Collections.ArrayList; using FRMS = System.Windows.Forms; using App = System.Windows.Forms.Application; /// <summary> /// Summary description for clsWord /// </summary> public class clsWord { /// <summary> ///Constructors and Destructor ///Base Constructor /// </summary> public clsWord(bool blnMyAppVisible){this.blnAppVisible = blnMyAppVisible;} ~clsWord() {} /// <summary> ///Variables Declaration /// </summary> private static object missing = Reflection.Missing.Value; private Word.Application wrdApp = new Word.Application(); private Word.Document wrdDocument; private int intRow; private int intCol; private bool blnAppVisible; /// <summary> //Property Declaration /// </summary> /// <summary> //Method Declaration /// </summary> public void DataSetExport(ref FRMS.StatusBar sbMyStatusBar,ref C1.Win.C1TrueDBGrid.C1TrueDBGrid C1MyTrueDBGrid ,int intMyRowCount,ref C1.Win.C1TrueDBGrid.SelectedRowCollection arrMySelRows,ref ArrayList arrColumns, ref FRMS.ProgressBar prgMyProgressBar) { try { clsGlobal.Cursor_0.Hourglass(); if (intMyRowCount ==0){goto End;} wrdApp.Visible = blnAppVisible; //Create new Word Document wrdDocument = new Word.Document(); Word.Documents wrdDocs = wrdApp.Documents; Word._Document my_Doc = (Word._Document) wrdDocument; wrdDocument = wrdDocs.Add(ref missing, ref missing, ref missing, ref missing); wrdDocument.PageSetup.Orientation = Word.WdOrientation.wdOrientLandscape; // //Add title to Word Document Word.Range wrdRange = wrdDocument.Range(ref missing,ref missing); // strFileName = "\t" + "\t" + "\t" + "\t" + strFileName + " TABLE \n"; // wrdRange.Text= strFileName; // //Format title to Word Document // Word.FontClass fc = new Word.FontClass(); // object objStart = 0; // object objEnd = strFileName.Length; // wrdRange=wrdDocument.Range(ref objStart, ref objEnd); // fc.Size=12; // fc.Bold=1; // fc.Color=Word.WdColor.wdColorBlack; // wrdRange.Font=fc; // wrdRange.Text= strFileName; //Define Table Properties(All rows or only Selected Rows) arrColumns.TrimToSize(); switch(arrMySelRows.Count) { case 0: wrdDocument.Tables.Add(wrdRange,intMyRowCount+1,arrColumns.Count,ref missing,ref missing); break; default: wrdDocument.Tables.Add(wrdRange,arrMySelRows.Count+1,arrColumns.Count,ref missing,ref missing); break; } Word.FontClass fc = new Word.FontClass(); fc.Size=10; fc.Bold=1; fc.Color=Word.WdColor.wdColorBlack;
intRow=1; for(intCol=1;intCol<=arrColumns.Count;++intCol) { wrdDocument.Tables.Item(1).Cell(intRow,intCol).Range.Text= C1MyTrueDBGrid.Columns[(System.Int32)arrColumns[intCol-1]].Caption; wrdDocument.Tables.Item(1).Cell(intRow,intCol).Range.Font = fc; sbMyStatusBar.Text = wrdDocument.Tables.Item(1).Cell(intRow,intCol).Range.Text; } fc.Size=10; fc.Bold=0; fc.Color=Word.WdColor.wdColorBlack; //Define Export Type (All rows or only Selected Rows) switch(arrMySelRows.Count) { case 0: goto ExportAll; default: goto ExportSel; } ExportAll:
//Create ProgressBar Class if is is not null if (prgMyProgressBar!=null) { prgMyProgressBar.Value=0; prgMyProgressBar.Minimum=0; prgMyProgressBar.Maximum=arrColumns.Count; prgMyProgressBar.Step=1; } for(intCol=1;intCol<=arrColumns.Count;++intCol) { C1MyTrueDBGrid.MoveFirst(); for(intRow=1;intRow<=intMyRowCount;++intRow) { wrdDocument.Tables
Ответить
|