C# Macros to format excel worksheet throws Exception...
-
Dienstag, 6. März 2012 05: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
Alle Antworten
-
Freitag, 9. März 2012 04:04Moderator
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
-
Dienstag, 13. März 2012 05: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
- Als Antwort vorgeschlagen cjatmsModerator Mittwoch, 28. März 2012 14:41
- Als Antwort markiert Bruce SongModerator Mittwoch, 4. April 2012 03:16
-
Dienstag, 13. März 2012 20:22Moderator
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 LeadChris Jensen

