问题简介:开发了一个winform控件主要是为实现Excel文档转成图片的功能。  
 
测试方式:通过一个html的测试调用<object  id="ExcelForm" classid    
 
=http:ExcelForm.dll#ExcelForm.Form3><script>  document("ExcelForm")....</script></object>  
 
测试情况:测试时,控件可以正常启动客户端的Excel,可以设定打印区域。  
 
错误提示:类Range的copypicture方法无效  
 
主要代码:  
public  static  object  Open(object  obj,  object  param)     //Excel调用的方法  
{  
bool[]  flags;  
 
object[]  locals1;  
 
locals1  =  new  object[]{RuntimeHelpers.GetObjectValue(param)};  
flags  =  new  bool[]{true};  
LateBinding.LateGet(obj,  null,  "Open",  locals1,  null,  flags);  
if  (!flags[0])  
{  
return  null;  
}  
else  
{  
return            param  =  RuntimeHelpers.GetObjectValue(locals1[0]);  
                                                 
}  
                         
}  
 
...  
 
//调用API函数  
 
[DllImport("user32.dll")]  
public  static  extern  int  FindWindow(string  strclassName,  string  strWindowName);  
[DllImport("user32.dll")]  
private  static  extern  int  SetParent(int  hWndChild,  int  hWndNewParent);  
...  
 
public  int  controlWnd  =  -1;  
this.filepath  =  Path.GetTempFileName();  
this.el  =  new  Excel.ApplicationClass();  
this.controlWnd  =  FindWindow("XLMain",  null);  
 
//调用上面的open方法  
             
Excel.Workbook  workbook  =  this.Open(this.el.Workbooks,  this.filepath_)  as  Excel.Workbook;  
this.el.Visible  =  true;  
this.el.DisplayAlerts  =  false;  
SetParent(this.controlWnd,  base.Handle.ToInt32());  
 
string  Filepath  =  Path.GetFileNameWithoutExtension(this.filepath);  
this.eSheet  =  (Excel.Worksheet)workbook.Sheets[Filepath];  
 
//下面这句执行成功  
 
this.eSheet.PageSetup.PrintArea  =  "A1:C9";  
 
//这句未执行,是出现错误的地方  
 
this.eSheet.get_Range("A1","C9").CopyPicture(Excel.XlPictureAppearance.xlPrinter,Excel.XlCop  
 
yPictureFormat.xlBitmap);  
 
问题出在什么地方,请在座的星星指点迷津。

解决方案 »

  1.   

    你的代码片段真的看不懂ms-help://MS.MSDNQTR.2003FEB.2052/modcore/html/deovrTheRangeProperty.htm
    理论上讲是能实现你的需求,但是要对vba编程极其的熟悉,自己到网上找找资料吧
    http://www.eliu.info/js1.asphttp://www.google.com/search?sourceid=navclient&hl=zh-CN&ie=UTF-8&rls=GGLD,GGLD:2005-12,GGLD:zh-CN&q=c%23+%E6%93%8D%E4%BD%9Cexcel