在asp.net中,有string aa = “数据A”,string bb = “数据B”;
我要将“数据A”导出到excel指定的单元格如B2中,“数据B”导出到D4单元格中,请问如何操作!其实我自己先设了个excel的模板,只是将一些数据填充进去,如何操作呢!

解决方案 »

  1.   

    链接EXCEL  
    当成数据源 select * from $sheet1
    然后结果转换成DataSet  
    接着对DataSet操作就OK了
     可以从这个思路考虑
      

  2.   


    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;
      

  3.   

    可以使用MyXls控件,操作Excel方便又简单
      

  4.   

    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();