示例#1
0
            public void TableCreateGenre(int row, int col, string[] header, Dictionary <string, double> dictionary)
            {
                Object start = 80;
                Object end   = 81;

                word.Range wordrange = worddocument.Range(ref start, ref end);
                //wordrange.InsertBreak(word.WdBreakType.wdPageBreak);
                wordrange.Bold = 400;
                Object defaultTableBehavior = word.WdDefaultTableBehavior.wdWord9TableBehavior;
                Object autoFitBehavior      = word.WdAutoFitBehavior.wdAutoFitWindow;

                word.Table wordtable = worddocument.Tables.Add(wordrange, row + 1, col, ref defaultTableBehavior, ref autoFitBehavior);

                for (int c = 1; c <= col; c++)
                {
                    word.Range wordcellrange = worddocument.Tables[1].Cell(1, c).Range;
                    wordcellrange.Text = header[c - 1];
                }

                int cellCounter = 2;

                foreach (var genre in dictionary)
                {
                    word.Range wordcellrange = worddocument.Tables[1].Cell(cellCounter, 1).Range;
                    wordcellrange.Text = (cellCounter - 1).ToString();
                    wordcellrange      = worddocument.Tables[1].Cell(cellCounter, 2).Range;
                    wordcellrange.Text = genre.Key;
                    wordcellrange      = worddocument.Tables[1].Cell(cellCounter, 3).Range;
                    wordcellrange.Text = genre.Value.ToString();
                    cellCounter++;
                }

                wordtable.AllowAutoFit = true;
                word.Column firstCol = wordtable.Columns[1];
                firstCol.AutoFit();
                Single firstColAutoWidth = firstCol.Width;

                wordtable.AutoFitBehavior(word.WdAutoFitBehavior.wdAutoFitWindow);
                firstCol.SetWidth(firstColAutoWidth, word.WdRulerStyle.wdAdjustFirstColumn);

                object rEnd   = worddocument.Content.End;
                int    rt     = (int)rEnd;
                object rStart = rt - 1;

                word.Range picRange = worddocument.Range(ref rStart, ref rEnd);

                picRange.InlineShapes.AddPicture(@"C:\Users\acer\Desktop\Учеба\АИС\Graf.bmp");
            }
示例#2
0
            public void TableCreateBook(int row, int col, string[] header, List <Book> books)
            {
                Object start = 94;
                Object end   = 95;

                word.Range wordrange = worddocument.Range(ref start, ref end);
                //wordrange.InsertBreak(word.WdBreakType.wdPageBreak);
                wordrange.Bold = 400;
                Object defaultTableBehavior = word.WdDefaultTableBehavior.wdWord9TableBehavior;
                Object autoFitBehavior      = word.WdAutoFitBehavior.wdAutoFitWindow;

                word.Table wordtable = worddocument.Tables.Add(wordrange, row + 1, col, ref defaultTableBehavior, ref autoFitBehavior);

                for (int c = 1; c <= col; c++)
                {
                    word.Range wordcellrange = worddocument.Tables[1].Cell(1, c).Range;
                    wordcellrange.Text = header[c - 1];
                }

                for (int i = 0; i < row; i++)
                {
                    word.Range wordcellrange = worddocument.Tables[1].Cell(i + 2, 1).Range;
                    wordcellrange.Text = $"{books[i].Name} ({books[i].Type})";
                    wordcellrange      = worddocument.Tables[1].Cell(i + 2, 2).Range;
                    wordcellrange.Text = books[i].LitresEstimate.ToString();
                    wordcellrange      = worddocument.Tables[1].Cell(i + 2, 3).Range;
                    wordcellrange.Text = books[i].Description;
                }
                wordtable.AllowAutoFit = true;
                word.Column firstCol = wordtable.Columns[2];
                firstCol.AutoFit();
                Single firstColAutoWidth = firstCol.Width;

                wordtable.AutoFitBehavior(word.WdAutoFitBehavior.wdAutoFitWindow);
                firstCol.SetWidth(firstColAutoWidth, word.WdRulerStyle.wdAdjustFirstColumn);
            }