任何人都可以帮我导出excel作为数字而不是文本吗?另外,我想冻结第一行。这是我用来导出到excel的功能。另外,我希望行以交替颜色显示:
public FilePathResult ExportToExcel(){
log.Info("Action ExportToExcel for user " + User.Identity.GetUserName());
List<string> dataTypes = new List<string>();
NameValueCollection parameters = Request.Params;
string query = QueryUtility.ConstructQueryForExcel(parameters);
DataSet ds = new DataSet();
DataTable dt = DaoUtilitySingleton.Instance.ExecuteQueryToGetDataTable(query);
ds.Tables.Add(dt);
log.Info("Query for export " + query);
log.Info("Column names : " + parameters["columnNames"]);
string guid = Guid.NewGuid().ToString();
string fileName = guid;
fileName += System.DateTime.Now.Ticks.ToString();
fileName += ".xlsx";
string destinationPath = Path.Combine(
Server.MapPath("~/App_Data/ExcelExports"));
if (!Directory.Exists(destinationPath))
{
log.Info("Directory does not exist. Creating Directory first");
Directory.CreateDirectory(destinationPath);
}
destinationPath = Path.Combine(destinationPath, fileName);
log.Info("Excel file will be saved as " + destinationPath);
//currently , this function return data which is in text and not number
try
{
if (!(new ExcelUtility()).CreateExcelDocumentFromDataset(ds,
destinationPath))
{
log.Error("Excel file could not be created");
return null;
}
}
catch (Exception ex)
{
GeneralUtility.LogException(log,
"Excel file could not be created",
ex);
throw;
}
log.Info("FIle created successfully");
FilePathResult file = File(destinationPath, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Properties.Instance.FileForExcel);
return file;
//return the file
}