[asp.net/C#]如何向EXCEL中指定单元格传数据! 在asp.net中,有string aa = “数据A”,string bb = “数据B”;我要将“数据A”导出到excel指定的单元格如B2中,“数据B”导出到D4单元格中,请问如何操作!其实我自己先设了个excel的模板,只是将一些数据填充进去,如何操作呢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 链接EXCEL 当成数据源 select * from $sheet1然后结果转换成DataSet 接着对DataSet操作就OK了 可以从这个思路考虑 string filepath =@"c:\模板.xls"Excel.Application excel = new Excel.ApplicationClass(); excel.Visible = false; excel.DisplayAlerts = false; Excel.Workbooks workbooks = excel.Workbooks; Excel.Workbook workbook=workbooks.Open(filepath,Missing.Value,true,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value); Excel.Worksheet st =wb.Sheets[1] as Excel.Worksheet;// (Excel.Worksheet)wb.Sheets.Add(System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value); sheet.Cells[2, 2]=aa;sheet.Cells[4, 4]=bb; 可以使用MyXls控件,操作Excel方便又简单 Excel.Application app=new Application();Excel._Workbook book;Excel._Worksheet sheet;book=(Excel._Workbook)app.Workbooks.Open(strPath,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);sheet=(Excel._Worksheet)book.Sheets[1];sheet.Cells[2,"A"]="";book.Save(); book.Close(null,null,null); app.Workbooks.Close(); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(app); System.Runtime.InteropServices.Marshal.ReleaseComObject(book); System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet); sheet=null; book=null; app=null; GC.Collect(); 学完这本书后,找工作? asp.net关于生成静态网页存放在根目录下问题?+随机生成静态页面 ASP。NET連接SQL問題,在線等......謝謝! 求救,一个关于求和可能性的算法。想锻炼大脑的进 菜鸟求教,用户控件问题 (100分)问一个关于IE打印问题? 字符替换的问题! 分析器错误信息: 访问被拒绝,重启机器就又好了,为什么? 根目录的项目如何部署?因为ASP.net项目安装之后总是成了一个虚拟目录 为什么用datagrid无法实现分页?以下是所有代码! 现在网站页面设计还用不用框架的 如何统计某个文章查看次数
当成数据源 select * from $sheet1
然后结果转换成DataSet
接着对DataSet操作就OK了
可以从这个思路考虑
string filepath =@"c:\模板.xls"
Excel.Application excel = new Excel.ApplicationClass();
excel.Visible = false;
excel.DisplayAlerts = false;
Excel.Workbooks workbooks = excel.Workbooks;
Excel.Workbook workbook=workbooks.Open(filepath,Missing.Value,true,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value); Excel.Worksheet st =wb.Sheets[1] as Excel.Worksheet;// (Excel.Worksheet)wb.Sheets.Add(System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value,System.Reflection.Missing.Value);
sheet.Cells[2, 2]=aa;
sheet.Cells[4, 4]=bb;
Excel._Workbook book;
Excel._Worksheet sheet;
book=(Excel._Workbook)app.Workbooks.Open(strPath,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
sheet=(Excel._Worksheet)book.Sheets[1];
sheet.Cells[2,"A"]="";
book.Save();
book.Close(null,null,null);
app.Workbooks.Close();
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
sheet=null;
book=null;
app=null;
GC.Collect();