Example #1
0
        ////////////////////////////////////////////
        // 复制ClassBorder对象的内容
        public void clone(ClassBorder obd)
        {
            this.ArtStyle   = obd.ArtStyle;   // 进行赋值
            this.ArtWidth   = obd.ArtWidth;   // 进行赋值
            this.Color      = obd.Color;      // 进行赋值
            this.ColorIndex = obd.ColorIndex; // 进行赋值
            this.Creator    = obd.Creator;    // 进行赋值
            this.Inside     = obd.Inside;     // 进行赋值
            this.LineStyle  = obd.LineStyle;  // 进行赋值
            this.LineWidth  = obd.LineWidth;  // 进行赋值
            this.Visible    = obd.Visible;    // 进行赋值

            return;
        }
Example #2
0
        //////////////////////////
        public void clone(ClassBorders obds)
        {
            this.AlwaysInFront             = obds.AlwaysInFront;
            this.Count                     = obds.Count;
            this.Creator                   = obds.Creator;
            this.DistanceFrom              = obds.DistanceFrom;
            this.DistanceFromBottom        = obds.DistanceFromBottom;
            this.DistanceFromLeft          = obds.DistanceFromLeft;
            this.DistanceFromRight         = obds.DistanceFromRight;
            this.DistanceFromTop           = obds.DistanceFromTop;
            this.Enable                    = obds.Enable;
            this.EnableFirstPageInSection  = obds.EnableFirstPageInSection;
            this.EnableOtherPagesInSection = obds.EnableOtherPagesInSection;
            this.HasHorizontal             = obds.HasHorizontal;
            this.HasVertical               = obds.HasVertical;
            this.InsideColor               = obds.InsideColor;
            this.InsideColorIndex          = obds.InsideColorIndex;
            this.InsideLineStyle           = obds.InsideLineStyle;
            this.InsideLineWidth           = obds.InsideLineWidth;
            this.JoinBorders               = obds.JoinBorders;
            this.OutsideColor              = obds.OutsideColor;
            this.OutsideColorIndex         = obds.OutsideColorIndex;
            this.OutsideLineStyle          = obds.OutsideLineStyle;
            this.OutsideLineWidth          = obds.OutsideLineWidth;
            this.Shadow                    = obds.Shadow;
            this.SurroundFooter            = obds.SurroundFooter;
            this.SurroundHeader            = obds.SurroundHeader;

            this.m_hashBorder.Clear();


            ClassBorder bd = null;

            for (int i = (int)WdBorderType.wdBorderVertical; i <= (int)WdBorderType.wdBorderTop; i++)
            {
                bd = (ClassBorder)obds[(WdBorderType)i];

                if (bd != null)
                {
                    ClassBorder classBd = new ClassBorder();
                    classBd.clone(bd);

                    m_hashBorder[i] = classBd;
                }
            }

            return;
        }
Example #3
0
        string[,] WordTableToStringTable(Table tbl, out int numHandles, string tableName)
        {
            int rowCount = tbl.Rows.Count;
            int colCount = tbl.Columns.Count;

            // Some tables end with final row that contains comments.  Ignore this row.
            for (int r = 1; r <= rowCount; r++)
            {
                for (int c = 1; c <= colCount; c++)
                {
                    try
                    {
                        string entry = tbl.Cell(r, c).Range.Text;
                    }
                    catch (Exception)
                    {
                        // the column does not exist: stop parsing before this row
                        rowCount = r - 1;
                        break;
                    }
                }
            }


            string[,] stringTable = new string[rowCount, colCount];
            int handleStartRow = -1, handleEndRow = -1;
            int lastRow = 1;

            for (int r = 1; r <= rowCount; r++)
            {
                // get the border beneath this row.
                Cell        rr  = tbl.Cell(r, 1);
                Borders     bs  = rr.Borders;
                Border      b   = bs[WdBorderType.wdBorderBottom];
                WdLineStyle art = b.LineStyle;

                if (art == WdLineStyle.wdLineStyleDashDotStroked)
                {
                    handleStartRow = r;
                }
                if (art == WdLineStyle.wdLineStyleThinThickThinSmallGap)
                {
                    handleEndRow = r;
                }

                if (!(
                        art == WdLineStyle.wdLineStyleDashDotStroked ||
                        art == WdLineStyle.wdLineStyleThinThickThinSmallGap ||
                        art == WdLineStyle.wdLineStyleSingle))
                {
                    Debug.WriteLine("Table busted " + tableName + art.ToString());
                }

                for (int c = 1; c <= colCount; c++)
                {
                    try
                    {
                        stringTable[r - 1, c - 1] = TrimNonPrintable(tbl.Cell(r, c).Range.Text);
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Failed to parse table " + tableName);
                        continue;
                    }
                }
                lastRow = r;
            }
            if (handleStartRow > 0 && handleEndRow < 0)
            {
                handleEndRow = lastRow;
            }
            numHandles = 0;
            if (handleStartRow > 0)
            {
                numHandles = handleEndRow - handleStartRow;
            }
            return(stringTable);
        }
Example #4
0
        // 复制Word.Borders的对象到本类
        public void clone(Word.Borders obds)
        {
            this.AlwaysInFront = obds.AlwaysInFront; // 进行赋值
            this.Count         = obds.Count;         // 进行赋值
            this.Creator       = obds.Creator;       // 进行赋值

            try
            {
                this.DistanceFrom       = obds.DistanceFrom;       // 进行赋值
                this.DistanceFromBottom = obds.DistanceFromBottom; // 进行赋值
                this.DistanceFromLeft   = obds.DistanceFromLeft;   // 进行赋值
                this.DistanceFromRight  = obds.DistanceFromRight;  // 进行赋值
                this.DistanceFromTop    = obds.DistanceFromTop;    // 进行赋值
            }
            catch (System.Exception ex)
            {
            }
            finally
            {
            }

            this.Enable = obds.Enable;                                       // 进行赋值
            this.EnableFirstPageInSection  = obds.EnableFirstPageInSection;  // 进行赋值
            this.EnableOtherPagesInSection = obds.EnableOtherPagesInSection; // 进行赋值
            this.HasHorizontal             = obds.HasHorizontal;             // 进行赋值
            this.HasVertical       = obds.HasVertical;                       // 进行赋值
            this.InsideColor       = obds.InsideColor;                       // 进行赋值
            this.InsideColorIndex  = obds.InsideColorIndex;                  // 进行赋值
            this.InsideLineStyle   = obds.InsideLineStyle;                   // 进行赋值
            this.InsideLineWidth   = obds.InsideLineWidth;                   // 进行赋值
            this.JoinBorders       = obds.JoinBorders;                       // 进行赋值
            this.OutsideColor      = obds.OutsideColor;                      // 进行赋值
            this.OutsideColorIndex = obds.OutsideColorIndex;                 // 进行赋值
            this.OutsideLineStyle  = obds.OutsideLineStyle;                  // 进行赋值
            this.OutsideLineWidth  = obds.OutsideLineWidth;                  // 进行赋值
            this.Shadow            = obds.Shadow;                            // 进行赋值
            this.SurroundFooter    = obds.SurroundFooter;                    // 进行赋值
            this.SurroundHeader    = obds.SurroundHeader;                    // 进行赋值

            this.m_hashBorder.Clear();

            Border bd = null;

            // 将Border的各成员进行赋值
            for (int i = (int)WdBorderType.wdBorderVertical; i <= (int)WdBorderType.wdBorderTop; i++)
            {
                try
                {
                    bd = (Border)obds[(WdBorderType)i];
                }
                catch (System.Exception ex)
                {
                    continue;
                }

                if (bd != null)
                {
                    ClassBorder classBd = new ClassBorder();
                    classBd.clone(bd);

                    m_hashBorder[i] = classBd;
                }
            }

            return;
        }
Example #5
0
        public static void AddSimpleTable(Microsoft.Office.Interop.Word.Application WordApp, Document WordDoc, int numrows, int numcolumns, WdLineStyle outStyle, WdLineStyle intStyle)
        {
            Object Nothing = System.Reflection.Missing.Value;

            //文档中创建表格
            Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, ref Nothing, ref Nothing);
            //设置表格样式
            newTable.Borders.OutsideLineStyle = outStyle;
            newTable.Borders.InsideLineStyle  = intStyle;
            newTable.Columns[1].Width         = 100f;
            newTable.Columns[2].Width         = 220f;
            newTable.Columns[3].Width         = 105f;

            //填充表格内容
            newTable.Cell(1, 1).Range.Text = "产品详细信息表";
            newTable.Cell(1, 1).Range.Bold = 2;                                                              //设置单元格中字体为粗体
                                                                                                             //合并单元格
            newTable.Cell(1, 1).Merge(newTable.Cell(1, 3));
            WordApp.Selection.Cells.VerticalAlignment   = WdCellVerticalAlignment.wdCellAlignVerticalCenter; //垂直居中
            WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;       //水平居中

            //填充表格内容
            newTable.Cell(2, 1).Range.Text       = "产品基本信息";
            newTable.Cell(2, 1).Range.Font.Color = WdColor.wdColorDarkBlue; //设置单元格内字体颜色
                                                                            //合并单元格
            newTable.Cell(2, 1).Merge(newTable.Cell(2, 3));
            WordApp.Selection.Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;

            //填充表格内容
            newTable.Cell(3, 1).Range.Text = "品牌名称:";
            newTable.Cell(3, 2).Range.Text = "品牌名称:";
            //纵向合并单元格
            newTable.Cell(3, 3).Select();//选中一行
            object moveUnit   = WdUnits.wdLine;
            object moveCount  = 5;
            object moveExtend = WdMovementType.wdExtend;

            WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend);
            WordApp.Selection.Cells.Merge();


            newTable.Cell(12, 1).Range.Text = "产品特殊属性";
            newTable.Cell(12, 1).Merge(newTable.Cell(12, 3));

            //在表格中增加行
            WordDoc.Content.Tables[1].Rows.Add(ref Nothing);
        }