public void DataTableToExcel(DataTable dt,string path) { //instance excel object //Excel excel = new Excel(65536); Excel excel = new Excel(); //create a sheet excel.CreateSheet(dt.Columns); //write value into rows //excel.SetRowValue(dt.Rows); foreach (DataRow row in dt.Rows) { excel.SetRowValue(row); } // set excel protected excel.SetProtectPassword("etimes2011@", "baiyi"); // save excel file to local excel.SaveAs(path); }