C# Macros to format excel worksheet throws Exception...

답변됨 C# Macros to format excel worksheet throws Exception...

  • 2012년 3월 6일 화요일 오전 5:57
     
      코드 있음

    Hi friends,

           I am getting the exception while applying the formatting to the excel worksheet using Macros in C#..

           My C# application produces the output in Excel document.. The excel document consist of thousands of records and i wanted to produce line charts for the records.. So i used the Macros to create dynamic line charts and to apply some formatting style to the charts and contents of the worksheets...

          I succeeded in the creation of macros to apply format and to create line charts using C#. But I have a strange thing that occurs few times.. Many times it runs without any exceptions and sometimes it throws the exceptions while applying the formatting font name, size, its style and so on...

    The example code is follows..

    With Selection.Font
    .Name = "Calibri"
    .Size = 16
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ThemeColor = xlThemeColorAccent1
    .TintAndShade = -0.249977111117893
    .ThemeFont = xlThemeFontMinor
    End With

    The exception like cannot apply the style gets throws whenever i apply the formatting..

    Kindly help me to solve this issue..

    Thakns in advance..

    regards,


    Madankumar

모든 응답

  • 2012년 3월 9일 금요일 오전 4:04
    중재자
     
     

    Hi Madankumar,

    Thanks for posting in the MSDN Forum.

    As you said "But I have a strange thing that occurs few times.. Many times it runs without any exceptions and sometimes it throws the exceptions while applying the formatting font name, size, its style and so on...". I want to know the expection's details. And I also want to reproduce your issue on my side. So I need your Excel version and Visual Studio version.

    Have a good day,

    Tom 


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

  • 2012년 3월 13일 화요일 오전 5:50
     
     답변됨

    Hi Tom,

        Very thanks for your reply..

        For now, I am not receiving those errors since I changed the font styles to the "Times New Roman" and basic formatting.. The error messages I got before was like Cannot apply the "Font Name and Styles" to the particular range..

    regards,


    Madankumar

  • 2012년 3월 13일 화요일 오후 8:22
    중재자
     
     

    Hi Madankumar,

    Good news. Changing the font has stopped the error. Some of the other browsers in
    this Forum may be able to suggest how to substitute multiple fonts to give your
    graph the format you want.

    You can see the equivalent of the required C# code by recording a VBA macro in
    Excel then following that in your C# project.

    You said you were getting an Exception before but didn’t share the explicit wording
    of that exception message. The exact wording can be a useful query string to
    use when browsing the VKB for similar occurrences of that message.

    If you need more responsive help you should include a post with instructions on
    how to build a project similar to yours, or links to a SkyDrive workspace where
    you have saved a zip of your C# project.

    Regards,
    Chris Jensen
    Senior Technical Support Lead



    Chris Jensen