Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     PowerPoint.Selection sel = app.ActiveWindow.Selection;
     if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone)
     {
         MessageBox.Show("请选中需要统一文字的页面或文本框");
     }
     else if (sel.Type == PowerPoint.PpSelectionType.ppSelectionSlides)
     {
         PowerPoint.SlideRange srange = sel.SlideRange;
         foreach (PowerPoint.Slide slide in srange)
         {
             int count = slide.Shapes.Count;
             for (int i = 1; i <= count; i++)
             {
                 if (slide.Shapes[i].HasTextFrame == Office.MsoTriState.msoTrue)
                 {
                     if (slide.Shapes[i].TextFrame.HasText == Office.MsoTriState.msoTrue)
                     {
                         PowerPoint.ParagraphFormat pf = slide.Shapes[i].TextFrame.TextRange.ParagraphFormat;
                         if (checkBox1.Checked)
                         {
                             slide.Shapes[i].TextFrame.TextRange.Font.Name        = font.Name;
                             slide.Shapes[i].TextFrame.TextRange.Font.NameFarEast = font.Name;
                             if (font.Style == FontStyle.Italic)
                             {
                                 slide.Shapes[i].TextFrame.TextRange.Font.Italic = Office.MsoTriState.msoTrue;
                             }
                             if (font.Style == FontStyle.Bold)
                             {
                                 slide.Shapes[i].TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoTrue;
                             }
                         }
                         if (checkBox2.Checked)
                         {
                             slide.Shapes[i].TextFrame.TextRange.Font.Size = float.Parse(textBox1.Text.Trim());
                         }
                         if (checkBox3.Checked)
                         {
                             slide.Shapes[i].TextFrame.TextRange.Font.Color.RGB = panel1.BackColor.R + panel1.BackColor.G * 256 + panel1.BackColor.B * 256 * 256;
                         }
                         if (checkBox4.Checked)
                         {
                             pf.WordWrap    = Office.MsoTriState.msoTrue;
                             pf.SpaceWithin = float.Parse(textBox2.Text.Trim());
                         }
                         if (checkBox5.Checked)
                         {
                             if (comboBox1.Text == "两端对齐")
                             {
                                 pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignJustify;
                             }
                             else if (comboBox1.Text == "左对齐")
                             {
                                 pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignLeft;
                             }
                             else if (comboBox1.Text == "右对齐")
                             {
                                 pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignRight;
                             }
                             else if (comboBox1.Text == "居中对齐")
                             {
                                 pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignCenter;
                             }
                             else if (comboBox1.Text == "分散对齐")
                             {
                                 pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignDistribute;
                             }
                             else if (comboBox1.Text == "顶部对齐")
                             {
                                 slide.Shapes[i].TextFrame.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorTop;
                             }
                             else if (comboBox1.Text == "中部对齐")
                             {
                                 slide.Shapes[i].TextFrame.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorMiddle;
                             }
                             else if (comboBox1.Text == "底部对齐")
                             {
                                 slide.Shapes[i].TextFrame.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorBottom;
                             }
                         }
                     }
                     if (slide.Shapes[i].TextFrame2.HasText == Office.MsoTriState.msoTrue)
                     {
                         if (checkBox1.Checked)
                         {
                             slide.Shapes[i].TextFrame2.TextRange.Font.Name        = font.Name;
                             slide.Shapes[i].TextFrame2.TextRange.Font.NameFarEast = font.Name;
                             if (font.Style == FontStyle.Italic)
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.Font.Italic = Office.MsoTriState.msoTrue;
                             }
                             if (font.Style == FontStyle.Bold)
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoTrue;
                             }
                         }
                         if (checkBox2.Checked)
                         {
                             slide.Shapes[i].TextFrame2.TextRange.Font.Size = float.Parse(textBox1.Text.Trim());
                         }
                         if (checkBox3.Checked)
                         {
                             slide.Shapes[i].TextFrame2.TextRange.Font.Fill.BackColor.RGB = panel1.BackColor.R + panel1.BackColor.G * 256 + panel1.BackColor.B * 256 * 256;
                         }
                         if (checkBox4.Checked)
                         {
                             slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.WordWrap    = Office.MsoTriState.msoTrue;
                             slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.SpaceWithin = float.Parse(textBox2.Text.Trim());
                         }
                         if (checkBox5.Checked)
                         {
                             if (comboBox1.Text == "两端对齐")
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignJustify;
                             }
                             else if (comboBox1.Text == "左对齐")
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignLeft;
                             }
                             else if (comboBox1.Text == "右对齐")
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignRight;
                             }
                             else if (comboBox1.Text == "居中对齐")
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignCenter;
                             }
                             else if (comboBox1.Text == "分散对齐")
                             {
                                 slide.Shapes[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignDistribute;
                             }
                             else if (comboBox1.Text == "顶部对齐")
                             {
                                 slide.Shapes[i].TextFrame2.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorTop;
                             }
                             else if (comboBox1.Text == "中部对齐")
                             {
                                 slide.Shapes[i].TextFrame2.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorMiddle;
                             }
                             else if (comboBox1.Text == "底部对齐")
                             {
                                 slide.Shapes[i].TextFrame2.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorBottom;
                             }
                         }
                     }
                 }
             }
         }
     }
     else if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes)
     {
         PowerPoint.ShapeRange range = sel.ShapeRange;
         if (sel.HasChildShapeRange)
         {
             range = sel.ChildShapeRange;
         }
         int count = range.Count;
         for (int i = 1; i <= count; i++)
         {
             if (range[i].HasTextFrame == Office.MsoTriState.msoTrue)
             {
                 if (range[i].TextFrame.HasText == Office.MsoTriState.msoTrue)
                 {
                     PowerPoint.ParagraphFormat pf = range[i].TextFrame.TextRange.ParagraphFormat;
                     if (checkBox1.Checked)
                     {
                         range[i].TextFrame.TextRange.Font.Name        = font.Name;
                         range[i].TextFrame.TextRange.Font.NameFarEast = font.Name;
                         if (font.Style == FontStyle.Italic)
                         {
                             range[i].TextFrame.TextRange.Font.Italic = Office.MsoTriState.msoTrue;
                         }
                         if (font.Style == FontStyle.Bold)
                         {
                             range[i].TextFrame.TextRange.Font.Bold = Office.MsoTriState.msoTrue;
                         }
                     }
                     if (checkBox2.Checked)
                     {
                         range[i].TextFrame.TextRange.Font.Size = float.Parse(textBox1.Text.Trim());
                     }
                     if (checkBox3.Checked)
                     {
                         range[i].TextFrame.TextRange.Font.Color.RGB = panel1.BackColor.R + panel1.BackColor.G * 256 + panel1.BackColor.B * 256 * 256;
                     }
                     if (checkBox4.Checked)
                     {
                         pf.WordWrap    = Office.MsoTriState.msoTrue;
                         pf.SpaceWithin = float.Parse(textBox2.Text.Trim());
                     }
                     if (checkBox5.Checked)
                     {
                         if (comboBox1.Text == "两端对齐")
                         {
                             pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignJustify;
                         }
                         else if (comboBox1.Text == "左对齐")
                         {
                             pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignLeft;
                         }
                         else if (comboBox1.Text == "右对齐")
                         {
                             pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignRight;
                         }
                         else if (comboBox1.Text == "居中对齐")
                         {
                             pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignCenter;
                         }
                         else if (comboBox1.Text == "分散对齐")
                         {
                             pf.Alignment = PowerPoint.PpParagraphAlignment.ppAlignDistribute;
                         }
                         else if (comboBox1.Text == "顶部对齐")
                         {
                             range[i].TextFrame.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorTop;
                         }
                         else if (comboBox1.Text == "中部对齐")
                         {
                             range[i].TextFrame.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorMiddle;
                         }
                         else if (comboBox1.Text == "底部对齐")
                         {
                             range[i].TextFrame.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorBottom;
                         }
                     }
                 }
                 if (range[i].TextFrame2.HasText == Office.MsoTriState.msoTrue)
                 {
                     if (checkBox1.Checked)
                     {
                         range[i].TextFrame2.TextRange.Font.Name        = font.Name;
                         range[i].TextFrame2.TextRange.Font.NameFarEast = font.Name;
                         if (font.Style == FontStyle.Italic)
                         {
                             range[i].TextFrame2.TextRange.Font.Italic = Office.MsoTriState.msoTrue;
                         }
                         if (font.Style == FontStyle.Bold)
                         {
                             range[i].TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoTrue;
                         }
                     }
                     if (checkBox2.Checked)
                     {
                         range[i].TextFrame2.TextRange.Font.Size = float.Parse(textBox1.Text.Trim());
                     }
                     if (checkBox3.Checked)
                     {
                         range[i].TextFrame2.TextRange.Font.Fill.BackColor.RGB = panel1.BackColor.R + panel1.BackColor.G * 256 + panel1.BackColor.B * 256 * 256;
                     }
                     if (checkBox4.Checked)
                     {
                         range[i].TextFrame2.TextRange.ParagraphFormat.WordWrap    = Office.MsoTriState.msoTrue;
                         range[i].TextFrame2.TextRange.ParagraphFormat.SpaceWithin = float.Parse(textBox2.Text.Trim());
                     }
                     if (checkBox5.Checked)
                     {
                         if (comboBox1.Text == "两端对齐")
                         {
                             range[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignJustify;
                         }
                         else if (comboBox1.Text == "左对齐")
                         {
                             range[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignLeft;
                         }
                         else if (comboBox1.Text == "右对齐")
                         {
                             range[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignRight;
                         }
                         else if (comboBox1.Text == "居中对齐")
                         {
                             range[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignCenter;
                         }
                         else if (comboBox1.Text == "分散对齐")
                         {
                             range[i].TextFrame2.TextRange.ParagraphFormat.Alignment = Office.MsoParagraphAlignment.msoAlignDistribute;
                         }
                         else if (comboBox1.Text == "顶部对齐")
                         {
                             range[i].TextFrame2.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorTop;
                         }
                         else if (comboBox1.Text == "中部对齐")
                         {
                             range[i].TextFrame2.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorMiddle;
                         }
                         else if (comboBox1.Text == "底部对齐")
                         {
                             range[i].TextFrame2.VerticalAnchor = Office.MsoVerticalAnchor.msoAnchorBottom;
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public string CheckFormat_SBox(int sldNum, string tshpName, DataTable dt, bool sCheck = false)
        {
            string sErr = null;

            try
            {
                CMsoTriState     msoObj   = new CMsoTriState();
                string           shpName  = Convert.ToString(dt.Rows[0]["Name"]);
                PowerPoint.Shape curShape = ActivePPT.Slides[sldNum].Shapes[tshpName];
                if (curShape.Line.Visible != msoObj.getMsoTriState(Convert.ToInt32(dt.Rows[0]["LineVisible"])))
                {
                    sErr = sErr + "Line Border" + '\n';
                }
                if (curShape.Fill.Visible != msoObj.getMsoTriState(Convert.ToInt32(dt.Rows[0]["FillVisible"])))
                //curShape.Fill.Transparency != Convert.ToInt32(dt.Rows[0]["FillTransparency"]))
                {
                    sErr = sErr + "Shape Fill" + '\n';
                }

                // -'-------------- Shape Size and Position ---------------

                float tempBottom = curShape.Top + curShape.Height;
                float shpLeft    = (float)Convert.ToDouble(dt.Rows[0]["ShapeLeft"]);
                float shpTop     = (float)Convert.ToDouble(dt.Rows[0]["ShapeTop"]);
                if (Convert.ToInt32(curShape.Left) != Convert.ToInt32(shpLeft) || Convert.ToInt32(curShape.Top) != Convert.ToInt32(shpTop))
                {
                    sErr = sErr + "Position Error" + '\n';
                }

                //float shpWidth = (float)Convert.ToDouble(dt.Rows[0]["ShapeWidth"]);
                //float shpHeight = (float)Convert.ToDouble(dt.Rows[0]["ShapeHeight"]);
                //-    Get the Margin from mapping -
                float leftMargin   = (float)Convert.ToDouble(dt.Rows[0]["MarginLeft"]);
                float RightMargin  = (float)Convert.ToDouble(dt.Rows[0]["MarginRight"]);
                float TopMargin    = (float)Convert.ToDouble(dt.Rows[0]["MarginTop"]);
                float BottomMargin = (float)Convert.ToDouble(dt.Rows[0]["MarginBottom"]);
                if (curShape.TextFrame.MarginLeft != leftMargin || curShape.TextFrame.MarginRight != RightMargin || curShape.TextFrame.MarginTop != TopMargin ||
                    curShape.TextFrame.MarginBottom != BottomMargin)
                {
                    sErr = sErr + "Margin Error" + '\n';
                }
                // '--------------------- Check the Font Error -------------------
                string     fontName  = dt.Rows[0]["FontName"].ToString();
                int        Bold      = Convert.ToInt32(dt.Rows[0]["Bold"]);
                int        Italics   = Convert.ToInt32(dt.Rows[0]["Italics"]);
                int        Underline = Convert.ToInt32(dt.Rows[0]["Underline"]);
                int        FontSize  = Convert.ToInt32(dt.Rows[0]["FontSize"]);
                List <int> rgbVal1   = msoObj.get_RGBValue(Convert.ToString(dt.Rows[0]["FontColor"]));                  // Set the Object


                PowerPoint.Font txtRangefont = curShape.TextFrame.TextRange.Font;

                int rgbCode = txtRangefont.Color.RGB;
                //int B = rgbCode/65536;
                //int G = (rgbCode - B * 65536) / 256;
                //int R = rgbCode - B * 65536 - G * 256;

                int r = rgbCode & 255;
                int g = rgbCode / 256 & 255;
                int b = rgbCode / 65536;//((rgbCode / 256) ^ 2) & 255;
                if (tshpName == "Text Box" || tshpName == "Quote Box")
                {
                    if (txtRangefont.Name != fontName)
                    {
                        sErr = sErr + "Font Error" + '\n';
                    }
                }
                else
                {
                    if (txtRangefont.Name != fontName || txtRangefont.Bold != msoObj.getMsoTriState(Bold) || txtRangefont.Italic != msoObj.getMsoTriState(Italics) ||
                        txtRangefont.Underline != msoObj.getMsoTriState(Underline) || txtRangefont.Size != FontSize ||
                        (rgbVal1[0] != b || rgbVal1[1] != g || rgbVal1[2] != r))              // Font Color is Fix --
                    {
                        sErr = sErr + "Font Error" + '\n';
                    }
                }
                //----- Check  Paragraph Error
                //--- Get a specification from mapping excel file
                int   prgBullet    = Convert.ToInt32(dt.Rows[0]["ParagraphBullet"]);
                int   prgAlignment = Convert.ToInt32(dt.Rows[0]["ParagraphAlignment"]);
                int   prghpun      = Convert.ToInt32(dt.Rows[0]["ParagraphHangingPunctuation"]);
                float prgbspace    = (float)Convert.ToDouble(dt.Rows[0]["ParagraphSpaceBefore"]);
                float prgaspace    = (float)Convert.ToDouble(dt.Rows[0]["ParagraphSpaceAfter"]);
                float prgwspace    = (float)Convert.ToDouble(dt.Rows[0]["ParagraphSpaceWithin"]);
                float prgflmargin  = (float)Convert.ToDouble(dt.Rows[0]["RulerLevel1FirstMargin"]);                   // It's not part of Paragraph format
                float prgllmargin  = (float)Convert.ToDouble(dt.Rows[0]["RulerLevel1LeftMargin"]);                    // It's not part of Paragraph format
                PowerPoint.ParagraphFormat prgformat = curShape.TextFrame.TextRange.ParagraphFormat;
                if (prgformat.Bullet.Type != msoObj.getPpBulletType(prgBullet) || prgformat.Alignment != msoObj.ParagraphFormatAlignment(prgAlignment) ||
                    prgformat.SpaceBefore != prgbspace || prgformat.SpaceAfter != prgaspace || prgformat.SpaceWithin != prgwspace)

                {
                    sErr = sErr + "Paragraph Error" + '\n';
                }
                // ---    Size and rotation type error
                int Rotaion     = Convert.ToInt32(dt.Rows[0]["Rotaion"]);
                int LARatio     = Convert.ToInt32(dt.Rows[0]["LockAspectRatio"]);
                int Orientation = Convert.ToInt32(dt.Rows[0]["Orientation"]);
                if (curShape.Rotation != Rotaion || curShape.TextFrame.Orientation != msoObj.getOrientation(Orientation) || curShape.LockAspectRatio != msoObj.getMsoTriState(LARatio))
                {
                    sErr = sErr + "Size and rotation" + '\n';
                }
                //getVerticalAnchor
                int shpAnchor = Convert.ToInt32(dt.Rows[0]["VerticalAnchor"]);//VerticalAnchor
                if (curShape.TextFrame.VerticalAnchor != msoObj.getVerticalAnchor(shpAnchor))
                {
                    sErr = sErr + "Vertical alengment error" + '\n';
                }
                //ppAutoSizeShapeToFitText  TxtAutoSize
                int autosize = Convert.ToInt32(dt.Rows[0]["AutoSize"]);//TxtAutoSize
                if (curShape.TextFrame.AutoSize != msoObj.TxtAutoSize(shpAnchor))
                {
                    sErr = sErr + "Shape tex fit error" + '\n';
                }
                //RulerLevel1LeftMargin
                //Activeshape.TextFrame.Ruler.Levels[1].LeftMargin
                int inlmargin = Convert.ToInt32(dt.Rows[0]["RulerLevel1LeftMargin"]);//LeftMargin
                if (curShape.TextFrame.Ruler.Levels[1].LeftMargin != inlmargin)
                {
                    sErr = sErr + "Paragraph indentation eror" + '\n';
                }
            }
            catch (Exception err)
            {
                string errtext = err.Message;
                PPTAttribute.ErrorLog(errtext, "CheckFormat_SBox");
            }
            return(sErr);
        }