Excel匯入匯出

2021-09-23 08:02:09 字數 2485 閱讀 4682

using system;

using system.collections.generic;

using system.data;

using system.io;

using system.linq;

using system.text;

using system.web;

using npoi.ss.usermodel;

using npoi.hssf.usermodel;

using npoi.xssf.usermodel;

using system.data.oledb;

namespace bll

else if (fileext == ".xls") else

if (workbook == null)

isheet sheet = string.isnullorempty(workbook.getsheetname(0)) ? workbook.getsheet("sheet1") : workbook.getsheet(workbook.getsheetname(0));

sheet.forceformularecalculation = true;

//資料  

for (int i = 0; i < dt.rows.count; i++)

}//轉為位元組陣列  

///

///

public static void tabletoexcelfile(datatable dt, string filepath, string spath, int count)

else if (fileext == ".xls") else

if (workbook == null)

isheet sheet = string.isnullorempty(workbook.getsheetname(0)) ? workbook.getsheet("sheet1") : workbook.getsheet(workbook.getsheetname(0));

sheet.forceformularecalculation = true;

icellstyle cellstyle = getcellstyle(workbook);

//設定單元格上下左右邊框線  

cellstyle.bordertop = npoi.ss.usermodel.borderstyle.thin;

cellstyle.borderbottom = npoi.ss.usermodel.borderstyle.thin;

cellstyle.borderleft = npoi.ss.usermodel.borderstyle.thin;

cellstyle.borderright = npoi.ss.usermodel.borderstyle.thin;

//資料  

for (int i = 0; i < dt.rows.count; i++)

}//轉為位元組陣列  

workbook.write(stream);

var buf = stream.toarray();

//儲存為excel檔案  

using (filestream fs = new filestream(filepath, filemode.create, fileaccess.write))

}catch (exception ex)

finally

}protected static icellstyle getcellstyle(iworkbook workbook)

///

/// 讀取excel資料

///

///

///

///

public static datatable exceltotable(string filepath, string strsql)

catch (exception ex)

finally

}///

/// 將excel中的資料匯入到datatable中

///

/// 檔名稱

/// 表頭行數

/// 資料總列數

///

public static datatable exceltotable(string filename, int startrow, int cellcount)}}

if (startrow <= 0)

startrow = sheet.firstrownum + 1;

//最後一列的標號

int rowcount = sheet.lastrownum;

for (int i = startrow; i <= rowcount; ++i)

data.rows.add(datarow);}}

return data;

}catch (exception ex)

finally}}

}

excel匯入匯出

匯出 yii框架中 header content disposition attachment filename 123.xls arr connection createcommand select from recruit queryall array this db get recruit r...

EXCEL匯入匯出

系統管理員登入,系統下資源管理 分機號列表內容匯出 suppresswarnings rawtypes responsebody public jsonobject selectfenjihaoinxitongforexportbyparam requestparam value fenjihao ...

excel匯入匯出

匯出 匯出相對比較簡單在控制層的關鍵 為 string filename 成果資料 dateutils.getdate yyyymmddhhmmss xlsx listpersonneltitlelist personneltitleservice.findlist personneltitle n...