Programmatically (C#) convert Excel to an image

前端 未结 6 787
轻奢々
轻奢々 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:54

    Because asp.net thread does not have the right ApartmentState to access Clipboard Class, so you must write code to access Clipboard in new thread. For example:

    private void AccessClipboardThread()
    {
        // access clipboard here normaly
    }
    

    in main thread:

    ....
    Excel.Range range = sheet.get_Range(startRange, endRange); //Save range image to clipboard
    Thread thread = new Thread(new ThreadStart(AccessClipboardThread));
    thread.ApartmentState = ApartmentState.STA;
    thread.Start();
    thread.Join(); //main thread will wait until AccessClipboardThread finish.
    ....
    

提交回复
热议问题