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

    Pertanyaan

  • 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

    06 Maret 2012 5:57

Jawaban

  • 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

    • Disarankan sebagai Jawaban oleh cjatmsModerator 28 Maret 2012 14:41
    • Ditandai sebagai Jawaban oleh Bruce Song 04 April 2012 3:16
    13 Maret 2012 5:50

Semua Balasan

  • 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

    09 Maret 2012 4:04
    Moderator
  • 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

    • Disarankan sebagai Jawaban oleh cjatmsModerator 28 Maret 2012 14:41
    • Ditandai sebagai Jawaban oleh Bruce Song 04 April 2012 3:16
    13 Maret 2012 5:50
  • 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

    13 Maret 2012 20:22
    Moderator