C#实现快速将数据写入Excel单元格
public void WriteArrayToExcel(object[,] dataobj,ExcelApplication excel,int ActiveSheetId,int StartRowId,int StartColId)
{
Excel.Range _range;
int arraywidth=dataobj.GetLength(1);
int arrayheight=dataobj.GetLength(0);
Worksheet worksheet = (Worksheet) excel.Worksheets[ActiveSheetId];
worksheet.Activate();
ArrayList ex_x = new ArrayList();
ArrayList ex_y = new ArrayList();
ArrayList ex_value = new ArrayList();
object _fvalue="";
int _maxlen=910;
for(int j=0;j { for(int k=0;k { _fvalue=dataobj[j,k];// field value //备份每个第911个单元数据 if(_fvalue.GetType().ToString()=="System.String") { if(((string)_fvalue).Length>_maxlen) { ex_x.Add(j+StartRowId); ex_y.Add(k+StartColId); ex_value.Add(_fvalue); _fvalue=""; }// end maxlen } dataobj[j,k]=_fvalue; }//end columns }// end rows _range=excel.Range[excel.Cells[StartRowId,StartColId],excel.Cells[StartRowId+arrayheight-1,StartColId+arraywidth-1]]; _range.get_Resize(arrayheight,arraywidth); _range.Value2=dataobj; //恢复重写对应的单元格 for(int j=0;j { excel.Cells[ex_x[j],ex_y[j]]=ex_value[j].ToString(); } } //end writearraytoexcel