コード例 #1
0
 /// <summary>
 /// シートの「SAMPLE」文字をすべて削除します。
 /// </summary>
 /// <param name="worksheet"></param>
 private void RemoveSampleText(Excel.Worksheet worksheet, RemoveSample removeSample)
 {
     foreach (dynamic shape in worksheet.Shapes)
     {
         try
         {
             if (shape.TextFrame2.TextRange.Count == 1 && shape.TextFrame2.TextRange.Text == removeSample.Text)
             {
                 // 削除
                 shape.Delete();
             }
         }
         catch (Exception e)
         {
             // コメント等、TextFrame2やTextRangeを実装していないクラスに対してはExceptionをスルーします
             if (!(e is System.NotImplementedException || e is System.ArgumentException))
             {
                 throw e;
             }
         }
     }
 }
コード例 #2
0
ファイル: Config.cs プロジェクト: steelplus/ExcelFormatter
        private static Config CreateConfig()
        {
            SelectA1 selectA1 = new SelectA1
            {
                ApplyTemplateSheetRegex   = ".*",
                ExcludeTemplateSheetRegex = ""
            };

            RemoveSample removeSample = new RemoveSample
            {
                ApplyTemplateSheetRegex   = ".*",
                ExcludeTemplateSheetRegex = "",
                Text = "SAMPLE"
            };

            Font font = new Font
            {
                ApplyTemplateSheetRegex   = ".*",
                ExcludeTemplateSheetRegex = "",
                FontName = "MS 明朝"
            };

            PageSetup pageSetup = new PageSetup
            {
                ApplyTemplateSheetRegex   = ".*",
                ExcludeTemplateSheetRegex = "",
                TopMargin     = 1,
                BottmonMargin = 1,
                LeftMargin    = 1,
                RightMargin   = 1,
                HeaderMargin  = 0.5,
                FooterMargin  = 0.5,
                Zoom          = 100,
                PaperSize     = "xlPaperA4",
                Orientation   = "xlLandscape"
            };

            Header header = new Header
            {
                ApplyTemplateSheetRegex   = ".*",
                ExcludeTemplateSheetRegex = "",
                CenterHeader = "",
                LeftHeader   = "",
                RightHeader  = ""
            };

            Footer footer = new Footer
            {
                ApplyTemplateSheetRegex   = ".*",
                ExcludeTemplateSheetRegex = "",
                CenterFooter = "",
                LeftFooter   = "",
                RightFooter  = ""
            };

            Config config = new Config
            {
                SelectA1     = selectA1,
                RemoveSample = new List <RemoveSample> {
                    removeSample
                },
                AddSample = new List <AddSample>(),
                Template  = new List <Template>(),
                Font      = new List <Font> {
                    font
                },
                PageSetup = new List <PageSetup> {
                    pageSetup
                },
                Header = new List <Header> {
                    header
                },
                Footer = new List <Footer> {
                    footer
                }
            };

            return(config);
        }