示例#1
0
        //TODO: animation test

        //some fixtures, these should prob end up in their own files. Not quite sure what to do with them in C# yet.
        private TildaTextbox oneSentenceFixture()
        {
            PowerPoint.Shape shape = new MockShape();
            int id = 15;

            Microsoft.Office.Core.TextRange2 tr = shape.TextFrame2.TextRange;
            tr.Text     = "Paragraph1";
            shape.Left  = 7f;
            shape.Width = 100f;
            shape.TextFrame2.MarginLeft  = 1.1f;
            shape.TextFrame2.MarginRight = 1.2f;
            tr.Font.Name = "Verdana";
            tr.Font.Size = 12f;
            tr.ParagraphFormat.SpaceBefore = 5.2f;
            int redRGB = 16711680;

            tr.Font.Fill.ForeColor.RGB = redRGB;
            shape.TextFrame2.TextRange.ParagraphFormat.Alignment = Microsoft.Office.Core.MsoParagraphAlignment.msoAlignLeft;
            shape.TextFrame2.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
            return(new TildaTextbox(shape, id));
        }
示例#2
0
        private TildaTextbox multiLevelParagraphBulletsFixture()
        {
            PowerPoint.Shape shape = new MockShape();
            int id = 15;

            Microsoft.Office.Core.TextRange2 tr = shape.TextFrame2.TextRange;
            // ` character is a level 1 bullet when the mock renders
            tr.Text     = "`Bullet1~Test2\r^Bullet2~\r*Bullet3";
            shape.Left  = 7f;
            shape.Width = 100f;
            shape.TextFrame2.MarginLeft  = 1.1f;
            shape.TextFrame2.MarginRight = 1.2f;
            tr.Font.Name = "Verdana";
            tr.Font.Size = 12f;
            tr.ParagraphFormat.SpaceBefore = 5.2f;
            tr.ParagraphFormat.SpaceAfter  = 5.2f;
            int redRGB = 16711680;

            tr.Font.Fill.ForeColor.RGB = redRGB;
            shape.TextFrame2.TextRange.ParagraphFormat.Alignment = Microsoft.Office.Core.MsoParagraphAlignment.msoAlignLeft;
            shape.TextFrame2.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
            return(new TildaTextbox(shape, id));
        }
示例#3
0
        private TildaTextbox bulletsAndTextFixture(Microsoft.Office.Core.MsoNumberedBulletStyle style = Microsoft.Office.Core.MsoNumberedBulletStyle.msoBulletArabicPeriod)
        {
            PowerPoint.Shape shape = new MockShape();
            int id = 15;

            Microsoft.Office.Core.TextRange2 tr = shape.TextFrame2.TextRange;
            // ` character is a level 1 bullet when the mock renders
            tr.Text     = "some test here and such\rmore text here and such\rand more\r`Bullet1\r`Bullet2";
            shape.Left  = 7f;
            shape.Width = 100f;
            shape.TextFrame2.MarginLeft  = 1.1f;
            shape.TextFrame2.MarginRight = 1.2f;
            tr.Font.Name = "Verdana";
            tr.Font.Size = 12f;
            tr.ParagraphFormat.SpaceBefore  = 5.2f;
            tr.ParagraphFormat.SpaceAfter   = 5.2f;
            tr.ParagraphFormat.Bullet.Style = style;
            int redRGB = 16711680;

            tr.Font.Fill.ForeColor.RGB = redRGB;
            shape.TextFrame2.TextRange.ParagraphFormat.Alignment = Microsoft.Office.Core.MsoParagraphAlignment.msoAlignLeft;
            shape.TextFrame2.VerticalAnchor = Microsoft.Office.Core.MsoVerticalAnchor.msoAnchorTop;
            return(new TildaTextbox(shape, id));
        }
示例#4
0
        private void DisplayShapeInfo(Shape shape)
        {
            string textFrame  = "";
            string textFrame2 = "";
            string Id         = "";
            string name       = "";
            string dashStyle  = "";
            string BackColor  = "";
            string foreColor  = "";

            try
            {
                Id = shape.Id.ToString();
            }
            catch (Exception ex)
            {
                Id = "<No Id>";
            }

            try
            {
                name = shape.Name;
            }
            catch (Exception ex)
            {
                name = "<No Name>";
            }

            try
            {
                dashStyle = shape.Line.DashStyle.ToString();
            }
            catch (Exception ex)
            {
                dashStyle = "<No DashStyle>";
            }

            try
            {
                BackColor = shape.Fill.BackColor.RGB.ToString();
            }
            catch (Exception ex)
            {
                BackColor = "<No BackColor>";
            }

            try
            {
                foreColor = shape.Fill.ForeColor.RGB.ToString();
            }
            catch (Exception ex)
            {
                foreColor = "<No ForeColor>";
            }

            string textFrameHyperlinkAddress    = "";
            string textFrameHyperlinkSubAddress = "";

            try
            {
                if (shape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                {
                    //textFrame = shape.TextFrame.TextRange.Text;
                    TextRange txtRange = shape.TextFrame.TextRange;

                    textFrame = txtRange.Text;

                    Hyperlink txtFrameHyperlink = txtRange.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink;

                    textFrameHyperlinkAddress = txtFrameHyperlink.Address != null?txtFrameHyperlink.Address.ToString() : "null";

                    textFrameHyperlinkSubAddress = txtFrameHyperlink.SubAddress != null?txtFrameHyperlink.SubAddress.ToString() : "null";
                }
                else
                {
                    textFrame = "";
                }
            }
            catch (Exception ex)
            {
                Common.WriteToDebugWindow("ex shape.TextFrame.HasText");
            }

            string textFrame2HyperlinkAddress;
            string textFrame2HyperlinkSubAddress;

            try
            {
                if (shape.TextFrame2.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                {
                    Microsoft.Office.Core.TextRange2 txtRange2 = shape.TextFrame2.TextRange;

                    textFrame2 = txtRange2.Text;

                    //Hyperlink txtFrame2Hyperlink = txtRange2.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink;

                    //textFrame2HyperlinkAddress = txtFrame2Hyperlink.Address != null ? txtFrame2Hyperlink.Address.ToString() : "null";
                    //textFrame2HyperlinkSubAddress = txtFrame2Hyperlink.SubAddress != null ? txtFrame2Hyperlink.SubAddress.ToString() : "null";
                }
                else
                {
                    textFrame2 = "";
                }
            }
            catch (Exception ex)
            {
                Common.WriteToDebugWindow("ex shape.TextFrame2.HasText");
            }

            ActionSetting mouseClick = shape.ActionSettings[PpMouseActivation.ppMouseClick];
            ActionSetting mouseOver  = shape.ActionSettings[PpMouseActivation.ppMouseOver];

            Hyperlink hyperlink = mouseClick.Hyperlink;


            string hyperLinkAddress = hyperlink.Address != null?hyperlink.Address.ToString() : "null";

            string hyperLinkSubAddress = hyperlink.SubAddress != null?hyperlink.SubAddress.ToString() : "null";

            string hyperLinkType = hyperlink.Type.ToString();

            Common.WriteToWatchWindow(string.Format("Id:{0,-6}  Name:{1,-20}  ForeColor:{2,-10}  BackColor:{3,-10}   DashStyle:{4,-10}   TextFrame:{5,-20}   TextFrame2:{6,-20}",
                                                    Id, name, foreColor, BackColor, dashStyle, textFrame, textFrame2));

            Common.WriteToWatchWindow(string.Format("Id:{0,-6}  textFrameHyperlinkAddress:{1,-20}  textFrameHyperlinkSubAddress:{2,-10}",
                                                    Id, textFrameHyperlinkAddress, textFrameHyperlinkSubAddress));

            Common.WriteToWatchWindow(string.Format("Id:{0,-6}  hyperLinkAddress:{1,-20}  hyperLinkSubAddress:{2,-10}  hyperLinkType:{3,-10}",
                                                    Id, hyperLinkAddress, hyperLinkSubAddress, hyperLinkType));
        }
示例#5
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                return(0);
            }

            // EXCELファイルパス
            string filePath = args[0];
            // EXCELファイルフルパス
            string fullPath = System.IO.Path.GetFullPath(filePath);

            // ファイルが無い場合終了
            if (!System.IO.File.Exists(fullPath))
            {
                return(0);
            }

            // シート名
            string strWorksheetName = "";
            // フォント名
            string fontName = args[1];

            //末端の改行文字を取り除く
            fontName.Trim();

            Microsoft.Office.Interop.Excel.Application xlApp        = null;
            Microsoft.Office.Interop.Excel.Workbooks   xlBooks      = null;
            Microsoft.Office.Interop.Excel.Workbook    xlBook       = null;
            Microsoft.Office.Interop.Excel.Sheets      xlSheets     = null;
            Microsoft.Office.Interop.Excel.Worksheet   xlSheet      = null;
            Microsoft.Office.Interop.Excel.Range       xlRange      = null;
            Microsoft.Office.Interop.Excel.Font        xlFont       = null;
            Microsoft.Office.Interop.Excel.Shapes      xlShapes     = null;
            Microsoft.Office.Interop.Excel.Shape       xlShape      = null;
            Microsoft.Office.Interop.Excel.TextFrame2  xlTextFrame2 = null;
            Microsoft.Office.Core.TextRange2           xlTextRange2 = null;
            Microsoft.Office.Core.Font2 xlFont2 = null;

            try
            {
                // EXCEL起動
                xlApp = new Microsoft.Office.Interop.Excel.Application();
                // EXCELは非表示にする
                xlApp.Visible = false;
                // 保存確認なしにする
                xlApp.DisplayAlerts = false;
                // Workbook開く
                xlBooks = xlApp.Workbooks;
                xlBook  = xlBooks.Open(fullPath);
                // Worksheet開く
                xlSheets = xlBook.Sheets;
                for (int ii = 1; ii <= xlSheets.Count; ++ii)
                {
                    xlSheet          = xlSheets.Item[ii];
                    strWorksheetName = xlSheet.Name;

                    // セルのフォントを変更する
                    xlRange     = xlSheet.UsedRange;
                    xlFont      = xlRange.Font;
                    xlFont.Name = fontName;
                    if (xlFont != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlFont);
                        xlFont = null;
                    }
                    if (xlRange != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange);
                        xlRange = null;
                    }

                    // 図形のフォントを変更する
                    xlShapes = xlSheet.Shapes;
                    for (int jj = 1; jj <= xlShapes.Count; ++jj)
                    {
                        xlShape      = xlShapes.Item(jj);
                        xlTextFrame2 = xlShape.TextFrame2;
                        if (xlTextFrame2.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                        {
                            xlTextRange2 = xlTextFrame2.TextRange;
                            xlFont2      = xlTextRange2.Font;

                            // 右から左へ記述するフォントの設定(例:アラビア語)
                            xlFont2.NameComplexScript = fontName;
                            // 全角フォントの設定(例:日本語)
                            xlFont2.NameFarEast = fontName;
                            // 半角フォントの設定(例:英語)
                            xlFont2.Name = fontName;

                            xlRange = xlShape.TopLeftCell;
                            System.Console.WriteLine(xlRange.Address + " [" + xlShape.Name + "]" + "のフォントを変更しました。");
                            if (xlRange != null)
                            {
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange);
                                xlRange = null;
                            }

                            if (xlFont2 != null)
                            {
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlFont2);
                                xlFont2 = null;
                            }
                            if (xlTextRange2 != null)
                            {
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlTextRange2);
                                xlTextRange2 = null;
                            }
                        }
                        if (xlTextFrame2 != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlTextFrame2);
                            xlTextFrame2 = null;
                        }
                        if (xlShape != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlShape);
                            xlShape = null;
                        }
                    }
                    if (xlShapes != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlShapes);
                        xlShapes = null;
                    }
                    if (xlSheet != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
                        xlSheet = null;
                    }
                    System.Console.WriteLine("処理が終了しました。シート名:" + strWorksheetName);
                }
                if (xlSheets != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);
                    xlSheets = null;
                }

                // Workbook保存
                xlBook.Save();
                System.Console.WriteLine("処理が終了しました。ファイル名:" + xlBook.Name);
            }
            catch
            {
                System.Console.WriteLine("ランタイムエラーが発生しました。シート名:" + strWorksheetName);
            }
            finally
            {
                if (xlFont2 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlFont2);
                    xlFont2 = null;
                }

                if (xlTextRange2 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlTextRange2);
                    xlTextRange2 = null;
                }

                if (xlTextFrame2 != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlTextFrame2);
                    xlTextFrame2 = null;
                }

                if (xlShape != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlShape);
                    xlShape = null;
                }

                if (xlShapes != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlShapes);
                    xlShapes = null;
                }

                if (xlFont != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlFont);
                    xlFont = null;
                }

                if (xlRange != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange);
                    xlRange = null;
                }

                if (xlSheet != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
                    xlSheet = null;
                }

                if (xlSheets != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);
                    xlSheets = null;
                }

                if (xlBook != null)
                {
                    xlBook.Close(false);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
                    xlBook = null;
                }

                if (xlBooks != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);
                    xlBooks = null;
                }

                if (xlApp != null)
                {
                    xlApp.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
                    xlApp = null;
                }
            }
            return(0);
        }