问题描述
解决方案
解决方案二:
代码如下publicExcel._Worksheetws;publicExcel.Rangerng;protectedvoidButton1_Click(objectsender,EventArgse){objectmissing=Type.Missing;Excel.Applicationexcel=newExcel.Application();stringpath=@"C:UsersfengpengfeiDownloads轴承案例信息表.xls";//stringpath=@"C:UsersfengpengfeiDesktop轴承.xlsx";Excel.Workbookwb=excel.Workbooks.Open(path,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing);Excel.Worksheetws=wb.Sheets[1];DataTabledt=WebHelper.ExecuteDataTable("selectPhotofromT_FaultInformation");DataRowCollectionrows=dt.Rows;DataRowrow=rows[0];stringstr=(string)row["Photo"];Label1.Text=str;excel.Visible=true;ws.Cells[1,11].Select();ws.Cells[1,11].EntireColumn.Delete(0);ws.Cells[2,11]="图片";InsertPicture(ws,str,30,30);//excel.Workbooks.Close();//excel.Quit();System.GC.Collect();System.GC.WaitForPendingFinalizers();//InsertPicture("excel.Cell[1,1]","Images\9.jpg",594.0f,154.0f);}publicvoidInsertPicture(Excel.Worksheetworksheet,stringPicturePath,floatPictuteWidth,floatPictureHeight){Excel.Rangerng=worksheet.Range[worksheet.Cells[4,11],worksheet.Cells[4,11]];rng.Select();floatPicLeft,PicTop;PicLeft=Convert.ToSingle(rng.Left)+2;PicTop=Convert.ToSingle(rng.Top)+2;//PicWidth=Convert.ToSingle(rng.Width);//PicHeight=Convert.ToSingle(rng.Height);//参数含义://图片路径//是否链接到文件//图片插入时是否随文档一起保存//图片在文档中的坐标位置(单位:points)//图片显示的宽度和高度(单位:points)//参数详细信息参见:http://msdn2.microsoft.com/zh-cn/library/aa221765(office.11).aspxworksheet.Shapes.AddPicture(PicturePath,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,PicLeft,PicTop,PictuteWidth,PictureHeight);//anShapes.PictureFormat.TransparentBackground=Microsoft.Office.Core.MsoTriState.msoTrue;//anShapes.PictureFormat.TransparencyColor=16777215;//白色//anShapes.Fill.Visible=Microsoft.Office.Core.MsoTriState.msoFalse;}如果是自己新建的表格(轴承.xlsx)这个程序可以往里面插入图片,但是打开用程序输出的表格(轴承案例信息表.xls)就不行,求大神指导啊
解决方案三:
木有人来回答啊。。。
解决方案四:
开发机的office组件没有配置正确