Programmatically (C#) convert Excel to an image

前端 未结 6 798
轻奢々
轻奢々 2020-12-29 11:32

I want to convert an excel file to an image (every format is ok) programmatically (c#). Currently I\'m using Microsoft Interop Libraries & Office 2007, but it does not s

6条回答
  •  太阳男子
    2020-12-29 11:37

    Interestingly I have been doing this in a STA compartment for some while with success. I wrote an app that runs on a weekly basis and mails out project status reports including some graphs I generate programmatically using Excel.

    Last night this failed the graphs all returned null. I'm debugging today and find no explanation just that the method Clipboard.GetImage() returns null suddenly which it did not. By setting a breakpoint at this call, I can effectively demonstrate (by pressing CTRL+V in MS-Word) that the image IS indeed in the clipboard. Alas continuing on Clipboard.GetImage() returns null (whether I'm snooping like this or not).

    My code runs as a console app and the Main method has the [STAThread] attribute. I debug it as a windows forms app (all my code is in a library and I simply have two front ends to that).

    Both return null today.

    Out of interest I spun off the chart fetcher into a thread as outlined (and note that thread.ApartmentState is deprecated), and it runs sweet, but still, nulls are returned.

    Well, I gave up and did what any IT geek would do, rebooted.

    Voila ... all was good. Go figure ... is this why we all loathe computers, Microsoft Windows and Microsoft Office? Hmmmm ... There is something , something entirely transient that can happen to you PC that makes Clipboard.GetImage() fail!

提交回复
热议问题