Esempio n. 1
0
 /// <summary>
 /// 在指定位置上插入表格
 /// </summary>
 /// <param name="type">插入类型</param>
 /// <param name="value">二维字符串数组</param>
 /// <param name="wordStyle">文字外观</param>
 public void WriteTableToDoc <T>(InsertionPoint type, T[,] value, WordTableStyle wordStyle = WordTableStyle.LightGrid)
 {
     try
     {
         int        rowCount = value.GetLength(0);
         int        colCount = value.GetLength(1);
         Word.Range r        = GetRange(type);
         Word.Table tab      = _wordTables.Add(r, rowCount, colCount);
         tab.set_Style(wordStyle);
         tab.Select();
         for (int i = 0; i < rowCount; i++)
         {
             for (int j = 0; j < colCount; j++)
             {
                 tab.Cell(i + 1, j + 1).Select();
                 _engine.Selection.TypeText(value[i, j].ToString());
             }
         }
     }
     catch (Exception ex)
     {
         ErrorParser(ex);
         return;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Metod koj kreira tabela vo dokumentot vo koja se zapisuvaat
        /// najprvo zaglavijata na kolonite, a potoa i
        /// polinjata so vrednostite za izvestajot
        /// </summary>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        public void CreateTable(int rowNum, int colNum)
        {
            object start = 0;
            object end   = 0;

            object styleName = "Table Grid 3";

            _wordRange = _wordApplication.ActiveDocument.Range(ref start, ref end);
            _wordApplication.ActiveDocument.Tables.Add(_wordRange, rowNum, colNum, ref _value, ref _value);
            _wordTable = _wordDocument.Tables[1];
            _wordTable.Range.Font.Size = 8;
            _wordTable.set_Style(ref styleName);

            for (int k = 0; k < colNum; k++)
            {
                _wordCell            = _wordTable.Cell(1, k + 1);
                _wordCell.Range.Text = (string)Headers[k];
            }


            for (int i = 0; i < rowNum; i++)
            {
                for (int j = 0; j < colNum; j++)
                {
                    _wordCell            = _wordTable.Cell(i + 2, j + 1);
                    _wordCell.Range.Text = Convert.ToString(FillValues[i, j]);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 设置基本的表格样式
 /// </summary>
 /// <param name="wordTable"></param>
 public static void SetTableStyle(Word.Table wordTable)
 {
     //设置表格格式
     try
     {                             //2007
         object styleName = "网格型"; // "Table Grid";
         wordTable.Range.Font.Size = 10;
         wordTable.set_Style(ref styleName);
     }
     catch (Exception e)
     { //2003
         try
         {
             object styleName = "Table Grid";
             //    wordTable.Range.Font.Size = 8;
             wordTable.set_Style(ref styleName);
         }
         catch (Exception e2)
         {
             Console.WriteLine(e2.Message + e.Message);
         }
     }
 }
Esempio n. 4
0
        //</Snippet82>


        //---------------------------------------------------------------------
        //<Snippet89>
        private void CreateDocumentPropertyTable()
        {
            //<Snippet90>
            object start = 0, end = 0;

            Word.Document document = this.Application.ActiveDocument;
            Word.Range    rng      = document.Range(ref start, ref end);
            //</Snippet90>

            // Insert a title for the table and paragraph marks.
            //<Snippet91>
            rng.InsertBefore("Document Statistics");
            rng.Font.Name = "Verdana";
            rng.Font.Size = 16;
            rng.InsertParagraphAfter();
            rng.InsertParagraphAfter();
            rng.SetRange(rng.End, rng.End);
            //</Snippet91>

            // Add the table.
            //<Snippet92>
            rng.Tables.Add(document.Paragraphs[2].Range, 3, 2, ref missing, ref missing);
            //</Snippet92>

            // Format the table and apply a style.
            //<Snippet93>
            Word.Table tbl = document.Tables[1];
            tbl.Range.Font.Size = 12;
            tbl.Columns.DistributeWidth();

            object styleName = "Table Professional";

            tbl.set_Style(ref styleName);
            //</Snippet93>

            // Insert document properties into cells.
            //<Snippet94>
            tbl.Cell(1, 1).Range.Text = "Document Property";
            tbl.Cell(1, 2).Range.Text = "Value";

            tbl.Cell(2, 1).Range.Text = "Subject";
            tbl.Cell(2, 2).Range.Text = ((Office.DocumentProperties)(document.BuiltInDocumentProperties))
                                        [Word.WdBuiltInProperty.wdPropertySubject].Value.ToString();

            tbl.Cell(3, 1).Range.Text = "Author";
            tbl.Cell(3, 2).Range.Text = ((Office.DocumentProperties)(document.BuiltInDocumentProperties))
                                        [Word.WdBuiltInProperty.wdPropertyAuthor].Value.ToString();
            //</Snippet94>
        }
Esempio n. 5
0
        private void ReportWord1()
        {
            Word.Application app = new Word.Application();
            app.Visible = true;
            Word.Document doc = app.Documents.Add();
            app.Selection.Font.Name = "Times New Roman";
            app.Selection.Font.Size = 14;
            app.Selection.Font.Bold = 1;
            app.Selection.TypeText("ОТЧЕТ О ПРОДАЖАХ ЗА " +
                                   dateTimePicker1.Value.ToShortDateString() +
                                   " - " + dateTimePicker2.Value.ToShortDateString());
            app.Selection.ParagraphFormat.Alignment =
                Word.WdParagraphAlignment.wdAlignParagraphCenter;
            app.Selection.TypeParagraph();
            app.Selection.ParagraphFormat.Alignment =
                Word.WdParagraphAlignment.wdAlignParagraphLeft;
            app.Selection.Font.Bold = 0;
            Word.Table t     = doc.Tables.Add(app.Selection.Range, 1, 5);
            Object     style = "Сетка таблицы";

            t.set_Style(style);
            Object unit = Word.WdUnits.wdCell;

            app.Selection.TypeText("Производитель");
            app.Selection.MoveRight(unit);
            app.Selection.TypeText("Товар");
            app.Selection.MoveRight(unit);
            app.Selection.TypeText("Клиент");
            app.Selection.MoveRight(unit);
            app.Selection.TypeText("Дата");
            app.Selection.MoveRight(unit);
            app.Selection.TypeText("Сумма продаж");
            report1TableAdapter1.Fill(kondirDataSet1.Report1,
                                      dateTimePicker1.Value, dateTimePicker2.Value);
            foreach (KondirDataSet.Report1Row r in kondirDataSet1.Report1)
            {
                app.Selection.MoveRight(unit);
                app.Selection.TypeText(r.SupplierName);
                app.Selection.MoveRight(unit);
                app.Selection.TypeText(r.ProductName);
                app.Selection.MoveRight(unit);
                app.Selection.TypeText(r.ClientName);
                app.Selection.MoveRight(unit);
                app.Selection.TypeText(r.SaleDate.ToShortDateString());
                app.Selection.MoveRight(unit);
                app.Selection.TypeText(r.Total.ToString());
            }
        }
Esempio n. 6
0
        protected void _SetTableStyle(ref Microsoft.Office.Interop.Word.Table table)
        {
            object style = "网格型";

            table.set_Style(ref style);

            //11/04/14加入
            //外边框颜色
            table.Rows.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleInset;
            table.Borders.OutsideColor         = Microsoft.Office.Interop.Word.WdColor.wdColorBlack;
            table.Borders.OutsideLineWidth     = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth150pt;
            //编写表格格式
            table.LeftPadding  = 0;
            table.RightPadding = 0;
            table.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
        }
        /// <summary>
        /// Add a Table to your Document with the specified number of Rows and Columns
        /// </summary>
        /// <param name="numRows"></param>
        /// <param name="numColumns"></param>
        /// <returns></returns>
        public static Word.Table AddTable(int numRows, int numColumns)
        {
            activeDocument.Tables.Add(Range: activeSelection.Range, NumRows: numRows, NumColumns: numColumns,
                                      DefaultTableBehavior: Word.WdDefaultTableBehavior.wdWord9TableBehavior, AutoFitBehavior: Word.WdAutoFitBehavior.wdAutoFitFixed);

            Word.Table table = activeSelection.Tables[1];
            table.set_Style("Table Grid");
            table.ApplyStyleHeadingRows = true;
            table.ApplyStyleLastRow     = false;
            table.ApplyStyleFirstColumn = true;
            table.ApplyStyleLastColumn  = false;
            table.ApplyStyleRowBands    = true;
            table.ApplyStyleColumnBands = false;

            return(table);
        }
 /// <summary>
 /// Called when [drop occurred].
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="data">The data.</param>
 public void OnDropOccurred(int x, int y, object data)
 {
     //Get the Word range from the form's point location
     Microsoft.Office.Interop.Word.Range range = (Microsoft.Office.Interop.Word.Range)Globals.ThisAddIn.Application.ActiveWindow.RangeFromPoint(x, y);
     //Insert a dummy details table for the selected order
     Word.Table table = this.Application.ActiveDocument.Tables.Add(range, 4, 4);
     table.Range.Font.Size = 8;
     table.set_Style("Table Grid 8");
     table.Rows[1].Cells[1].Range.Text = "Order Details";
     table.Rows[1].Cells[2].Range.Text = "Order Details";
     table.Rows[1].Cells[3].Range.Text = "Order Details";
     table.Rows[1].Cells[4].Range.Text = "Order Details";
     for (int i = 2; i < 5; i++)
     {
         for (int j = 1; j < 5; j++)
         {
             table.Rows[i].Cells[j].Range.Text = data.ToString();
         }
     }
 }
Esempio n. 9
0
        private void addDocument(Word.Table oTable, loepDocument document)
        {
            try { oTable.set_Style(Doc.Styles["Table Grid"].NameLocal); }
            catch { }
            oTable.Range.ParagraphFormat.SpaceAfter = 0;

            int fileExtPos = document.name.LastIndexOf(".");

            if (fileExtPos >= 0)
            {
                document.name = document.name.Substring(0, fileExtPos);
            }
            oTable.Rows[oTable.Rows.Count - 2].Range.Text          = document.name;
            oTable.Rows[oTable.Rows.Count - 2].Range.Font.Bold     = 1;
            oTable.Rows[oTable.Rows.Count - 2].Range.Font.Size     = 10;
            oTable.Rows[oTable.Rows.Count - 2].Range.Font.Position = 1;
            oTable.Rows[oTable.Rows.Count - 2].Cells[1].Merge(oTable.Rows[oTable.Rows.Count - 2].Cells[2]);
            oTable.Rows[oTable.Rows.Count - 2].Cells[1].Merge(oTable.Rows[oTable.Rows.Count - 2].Cells[2]);
            oTable.Rows[oTable.Rows.Count - 2].Cells[1].Merge(oTable.Rows[oTable.Rows.Count - 2].Cells[2]);
            oTable.Cell(oTable.Rows.Count - 2, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            oTable.Rows[oTable.Rows.Count - 1].Range.Font.Size = 10;
            oTable.Rows[oTable.Rows.Count].Range.Font.Size     = 9;
            oTable.Rows[oTable.Rows.Count - 1].Range.Font.Bold = 1;
            oTable.Cell(oTable.Rows.Count - 1, 1).Range.Text   = "From Page";
            oTable.Cell(oTable.Rows.Count - 1, 2).Range.Text   = "To Page";
            oTable.Cell(oTable.Rows.Count - 1, 3).Range.Text   = "Revision";
            oTable.Cell(oTable.Rows.Count - 1, 4).Range.Text   = "Date";
            oTable.Cell(oTable.Rows.Count - 1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Cell(oTable.Rows.Count - 1, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Cell(oTable.Rows.Count - 1, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Cell(oTable.Rows.Count - 1, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            oTable.Cell(oTable.Rows.Count, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Cell(oTable.Rows.Count, 2).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Cell(oTable.Rows.Count, 3).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Cell(oTable.Rows.Count, 4).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            addPages(document.location, oTable);
        }
Esempio n. 10
0
        public static void FormatTable()
        {
            Word.Application app   = Globals.ThisAddIn.Application;
            Word.Table       table = app.Selection.Range.Tables[1];

            for (int row = 1; row <= table.Rows.Count; row++)
            {
                for (int col = 1; col <= table.Columns.Count; col++)
                {
                    try {
                        table.Cell(row, col).Range.Select();
                        app.Selection.ClearFormatting();

                        if (row == 1)
                        {
                            table.Cell(row, col).Range.set_Style(app.ActiveDocument.Styles["2016_TableHeader | 10pt bold"]);
                        }
                        else
                        {
                            table.Cell(row, col).Range.set_Style(app.ActiveDocument.Styles["2016_Table | 9pt"]);
                        }
                    } catch (Exception f) {
                        Debug.Print(f.Message);
                    }
                }
            }

            table.set_Style(app.ActiveDocument.Styles["MasterTable"]);
            table.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
            table.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitWindow);

            try {
                table.Cell(1, 1).Row.HeadingFormat = (int)Word.WdConstants.wdToggle;
                table.ApplyStyleHeadingRows        = true;
            } catch (Exception) { };
        }
Esempio n. 11
0
File: Word.cs Progetto: Zagii/EAkzg
        public Wordy.Table wstawTabele(object bookmark, String[] naglowki)
        {
            Wordy.Bookmark book = doc.Bookmarks.get_Item(ref oEndOfDoc);

            Wordy.Table tab = doc.Tables.Add(book.Range, 1, naglowki.Count());
            //  tab.Range.ParagraphFormat.SpaceAfter = 6;

            object styleName = stylTab;

            tab.set_Style(ref styleName);

            int i = 1;

            foreach (String kol in naglowki)
            {
                Wordy.Cell cel = tab.Cell(1, i);
                cel.Range.Text = kol;
                object snorm = stylNorm;
                cel.Range.set_Style(ref snorm);
                i++;
            }

            return(tab);
        }
Esempio n. 12
0
        private void btnTarife_Click(object sender, EventArgs e)
        {
            Tarife = new Word.Application();

            Tarife.Visible = true;

            Word.Document wdoc = Tarife.Documents.Add();

            Word.Range wr = wdoc.Range();

            wr.Text = "\n\n" + "TARIFE HOTEL" + "\n\n\n";


            wr.Font.Name = "Segoe UI";

            wr.Font.Size = 14;

            wr.Font.Bold = -1;

            wdoc.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

            wr.Collapse(Word.WdCollapseDirection.wdCollapseEnd);

            Word.Table tabel = wr.Tables.Add(wr, 9, 2);

            wr.Collapse(Word.WdCollapseDirection.wdCollapseEnd);

            tabel.set_Style("Table Grid 8");

            tabel.Borders.Enable = 1;

            tabel.Cell(1, 1).Range.Text = "TIP CAMERĂ";

            tabel.Cell(1, 1).Range.Font.Size = 17;

            tabel.Cell(1, 2).Range.Text = "PREȚ PE NOAPTE";

            tabel.Cell(1, 2).Range.Font.Size = 17;

            con.Open();


            OleDbDataAdapter cmdTip = new OleDbDataAdapter("SELECT Tip_Camera, Pret_Noapte " +
                                                           "FROM Camere ", con);

            DataTable dtTip = new DataTable();

            cmdTip.Fill(dtTip);

            int nr = 0;

            int linie = 2;


            try
            {
                while (dtTip.Rows[nr][0].ToString() != "")
                {
                    tabel.Cell(linie, 1).Range.Text = dtTip.Rows[nr][0].ToString();

                    tabel.Cell(linie, 2).Range.Text = dtTip.Rows[nr][1].ToString() + " LEI";

                    nr += 1;

                    linie += 1;
                }
            }

            catch (Exception ex)
            {
            }



            tabel.Cell(linie, 1).Range.Text = "EXTRAOPȚIUNE";

            tabel.Cell(linie, 1).Range.Font.Size = 17;

            tabel.Cell(linie, 1).Range.Font.Bold = 0;

            tabel.Cell(linie, 1).Range.Font.Color = Word.WdColor.wdColorWhite;

            tabel.Cell(linie, 1).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorDarkBlue;

            tabel.Cell(linie, 2).Range.Text = "PREȚ";

            tabel.Cell(linie, 2).Range.Font.Size = 17;

            tabel.Cell(linie, 2).Range.Font.Bold = 0;

            tabel.Cell(linie, 2).Range.Font.Color = Word.WdColor.wdColorWhite;

            tabel.Cell(linie, 2).Range.Shading.BackgroundPatternColor = Word.WdColor.wdColorDarkBlue;



            OleDbDataAdapter cmdExtra = new OleDbDataAdapter("SELECT Denumire_Extraoptiune, Pret_Extraoptiune " +
                                                             "FROM Extraoptiuni ", con);

            DataTable dtExtra = new DataTable();

            cmdExtra.Fill(dtExtra);

            nr = 0;

            try
            {
                while (dtExtra.Rows[nr][0].ToString() != "")
                {
                    nr += 1;

                    linie += 1;

                    tabel.Cell(linie, 1).Range.Text = dtExtra.Rows[nr][0].ToString();

                    tabel.Cell(linie, 2).Range.Text = dtExtra.Rows[nr][1].ToString() + " LEI";
                }
            }

            catch (Exception ex)

            {
            }
        }
Esempio n. 13
0
        private void CreateDocumentPropertyTable(Document newDocument)
        {
            //<Snippet90>
            object start = 10, end = 10;

            Word.Range rangeTbl = null;
            string     keys     = "[tbl]";

            while (newDocument.Content.Find.Execute(FindText: keys))
            {
                if (newDocument.Content.Find.Execute(FindText: keys))
                {
                    if (newDocument.Application.Selection.Find.Execute(keys) == true)
                    {
                        rangeTbl = newDocument.Range(newDocument.Application.Selection.Range.Start, newDocument.Application.Selection.Range.End);
                    }
                }
            }

            //if (newDocument.Application.Selection.Find.Execute("[tbl]"))
            //{
            //    rangeTbl = newDocument.Range(newDocument.Application.Selection.Range.Start, newDocument.Application.Selection.Range.End);
            //}

            Word.Range rng = newDocument.Range(rangeTbl.Start, rangeTbl.End);
            //</Snippet90>

            // Insert a title for the table and paragraph marks.
            //<Snippet91>
            //rng.InsertBefore("Document Statistics");
            rng.Font.Name = "Calibri (Body)";
            rng.Font.Size = 16;
            rng.InsertParagraphAfter();
            rng.InsertParagraphAfter();
            rng.SetRange(rng.End, rng.End);
            //</Snippet91>

            // Add the table.
            //<Snippet92>
            rng.Tables.Add(newDocument.Paragraphs[2].Range, 3, 2);
            //</Snippet92>

            // Format the table and apply a style.
            //<Snippet93>
            Word.Table tbl = newDocument.Tables[1];
            tbl.Range.Font.Size = 12;
            tbl.Columns.DistributeWidth();

            object styleName = "Table Professional";

            tbl.set_Style(ref styleName);
            //</Snippet93>

            // Insert document properties into cells.
            //<Snippet94>
            tbl.Cell(1, 1).Range.Text = "Document Property";
            tbl.Cell(1, 2).Range.Text = "Value";

            tbl.Cell(2, 1).Range.Text = "Subject";
            tbl.Cell(2, 2).Range.Text = "Test";

            tbl.Cell(3, 1).Range.Text = "Author";
            tbl.Cell(3, 2).Range.Text = "test";
            //</Snippet94>
        }
Esempio n. 14
0
        /// <summary>
        /// 將 DataTable 插入至指定的 Word Range 位置
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="oRange"></param>
        /// <returns></returns>
        public static Word.Table CreateWordTableWithDataTable(DataTable dt, Word.Range oRange)
        {
            int RowCount    = dt.Rows.Count;
            int ColumnCount = dt.Columns.Count;

            Object[,] DataArray = new object[RowCount, ColumnCount];
            //int RowCount = 0; int ColumnCount = 0;
            int r = 0;

            for (int c = 0; c <= ColumnCount - 1; c++)
            {
                DataColumn dc = dt.Columns[c];
                object[]   colValues;
                #region    的資料型態轉換格式化
                if (dc.DataType == typeof(double))
                {
                    var o = dt.AsEnumerable().Select(x => Math.Round(x.Field <double>(dc.ColumnName), 4)).ToArray();
                    colValues = new object[o.Length];
                    o.CopyTo(colValues, 0);
                }
                else if (dc.DataType == typeof(DateTime))
                {
                    var o = dt.AsEnumerable().Select(x => string.Format("{0:yyyy-MM-dd hh:mm:ss}", x.Field <DateTime>(dc.ColumnName))).ToArray();
                    colValues = new object[o.Length];
                    o.CopyTo(colValues, 0);
                }
                else
                {
                    var o = dt.AsEnumerable().Select(x => x[dc.ColumnName]).ToArray();
                    colValues = new object[o.Length];
                    o.CopyTo(colValues, 0);
                }
                #endregion
                for (r = 0; r <= RowCount - 1; r++)
                {
                    DataArray[r, c] = colValues[r];
                } //end row loop
            }     //end column loop

            StringBuilder oTemp = new StringBuilder();
            for (r = 0; r <= RowCount - 1; r++)
            {
                for (int c = 0; c <= ColumnCount - 1; c++)
                {
                    oTemp.Append(DataArray[r, c] + "\t");
                }
            }

            oRange.Text = oTemp.ToString();
            object     Separator       = Word.WdTableFieldSeparator.wdSeparateByTabs;
            object     Format          = Word.WdTableFormat.wdTableFormatWeb1;
            object     ApplyBorders    = true;
            object     AutoFit         = true;
            object     AutoFitBehavior = Word.WdAutoFitBehavior.wdAutoFitContent;
            Word.Table tbl             = oRange.ConvertToTable(Separator: Separator,
                                                               NumRows: RowCount,
                                                               NumColumns: ColumnCount,
                                                               ApplyBorders: ApplyBorders, AutoFit: AutoFit, AutoFitBehavior: AutoFitBehavior);
            tbl.Rows.AllowBreakAcrossPages = 0;
            tbl.Rows.Alignment             = Word.WdRowAlignment.wdAlignRowCenter;
            tbl.Rows.Add(tbl.Rows[1]);
            //gotta do the header row manually
            for (int c = 0; c <= ColumnCount - 1; c++)
            {
                tbl.Cell(1, c + 1).Range.Text = dt.Columns[c].ColumnName;
            }
            tbl.set_Style(Word.WdBuiltinStyle.wdStyleTableLightGrid);
            return(tbl);
        }
Esempio n. 15
0
        private void btnExcel_Click(object sender, RibbonControlEventArgs e)
        {
            factura = new Word.Application();

            factura.Visible = true;

            Word.Document wdoc = factura.Documents.Add();

            Word.Range wr = wdoc.Range();

            wr.Text = "\n\n" + "FACTURĂ" + "\n\n\n";


            wr.Font.Name = "Segoe UI";

            wr.Font.Size = 14;

            wr.Font.Bold = -1;

            wdoc.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

            wr.Collapse(Word.WdCollapseDirection.wdCollapseEnd);

            Word.Table tabel = wr.Tables.Add(wr, 4, 2);

            wr.Collapse(Word.WdCollapseDirection.wdCollapseEnd);

            tabel.set_Style("Table Grid 8");

            tabel.Borders.Enable = 1;

            tabel.Cell(1, 1).Range.Text = "DENUMIRE";

            tabel.Cell(1, 1).Range.Font.Size = 17;

            tabel.Cell(1, 2).Range.Text = "DE PLĂTIT";

            tabel.Cell(1, 2).Range.Font.Size = 17;

            tabel.Cell(2, 1).Range.Text = "REZERVARE";

            tabel.Cell(3, 1).Range.Text = "ALTE CHELTUIELI";

            tabel.Cell(4, 1).Range.Text = "TOTAL";



            Excel.Application excel = Globals.ThisAddIn.Application;
            Excel.Worksheet   wsh   = excel.ActiveSheet;
            Excel.Range       rsh   = excel.Selection;



            con.Open();

            OleDbDataAdapter cmdInregistrari = new OleDbDataAdapter("SELECT (Pret_Noapte*(Data_Sfarsit-Data_Inceput)) AS TotalRez, Sum(Extraoptiuni.Pret_Extraoptiune) AS TotalEx " +
                                                                    "FROM Clienti INNER JOIN((Rezervari INNER JOIN(Camere INNER JOIN Camere_Rezervate ON Camere.Tip_Camera = Camere_Rezervate.Tip_Camera) ON Rezervari.NR_Inregistrare = Camere_Rezervate.NR_Inregistrare) INNER JOIN(Extraoptiuni INNER JOIN Extraoptiuni_Rezervare ON Extraoptiuni.Denumire_Extraoptiune = Extraoptiuni_Rezervare.Denumire_Extraoptiune) ON Rezervari.NR_Inregistrare = Extraoptiuni_Rezervare.NR_Inregistrare) ON Clienti.ID_Client = Rezervari.ID_Client " +
                                                                    "WHERE Rezervari.NR_Inregistrare Like '" + rsh.Value2.ToString() + "'" +
                                                                    "GROUP BY Rezervari.NR_Inregistrare, Rezervari.Data_Inceput, Rezervari.Data_Sfarsit, Camere.Pret_Noapte; ", con);
            DataTable dtInregistrari = new DataTable();

            cmdInregistrari.Fill(dtInregistrari);

            int a;

            int b;

            a = Int32.Parse(dtInregistrari.Rows[0][0].ToString());

            b = Int32.Parse(dtInregistrari.Rows[0][1].ToString());


            tabel.Cell(2, 2).Range.Text = dtInregistrari.Rows[0][0].ToString() + " LEI";

            tabel.Cell(3, 2).Range.Text = dtInregistrari.Rows[0][1].ToString() + " LEI";

            tabel.Cell(4, 2).Range.Text = (a + b).ToString() + " LEI";


            con.Close();
        }
Esempio n. 16
0
        private void button4_Click(object sender, EventArgs e)
        {
            OpenDocument($@"{_pathToDocumentDirectory}\список авто.docx");
            ReplaceText("<Today>", DateTime.Today.ToShortDateString());

            object start = 0;
            object end   = _wordDocument.Characters.Count;

            Word.Range rng = _wordDocument.Range(ref
                                                 start, ref end);
            rng.TextRetrievalMode.IncludeHiddenText = false;
            rng.TextRetrievalMode.IncludeFieldCodes = false;
            string metka = "<Table>";

            int beginphrase = rng.Text.IndexOf(metka);

            start = beginphrase;

            end = beginphrase + metka.Length;

            if (beginphrase != -1)
            {
                rng      = _wordDocument.Range(ref start, ref end);
                rng.Text = "";

                object defaultTableBehavior = Type.Missing;
                object autoFitBehavior      = Type.Missing;

                Word.Table tbl   = rng.Tables.Add(rng, 1, 4, ref defaultTableBehavior, ref autoFitBehavior);
                object     style = "Сетка таблицы";

                tbl.Range.Font.Size = 14;
                tbl.set_Style(ref style);
                tbl.Cell(1, 1).Range.Text = "№";
                tbl.Cell(1, 2).Range.Text = "Имя марки";
                tbl.Cell(1, 3).Range.Text = "Номер машины";
                tbl.Cell(1, 4).Range.Text = "Дата регистрации в ГАИ";

                int i = 0;

                foreach (Mark mark in dB_OwnersCarsDataSet.Mark)
                {
                    Car[] cars = mark.GetChildRows(dB_OwnersCarsDataSet.Relations["MarkCar"]) as Car[];

                    if (cars != null && cars.Length < 1 || cars == null)
                    {
                        continue;
                    }

                    string name = mark.MarkName;

                    foreach (Car car in cars)
                    {
                        i++;

                        object beforeRow = Type.Missing;

                        tbl.Rows.Add(ref beforeRow);

                        tbl.Cell(i + 1, 1).Range.Text = i.ToString();
                        tbl.Cell(i + 1, 2).Range.Text = name;
                        tbl.Cell(i + 1, 3).Range.Text = car.Number;
                        tbl.Cell(i + 1, 4).Range.Text = car.DateRegGAI.ToString();
                    }
                }

                tbl.Rows[1].Range.Font.Italic = 1;
                tbl.Rows[1].Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            }
            else
            {
                ReplaceText("Table", "");
            }

            _wordApplication.Visible = true;
        }