求解:导出Excel文件,数字字符串被强制转换成科学技术法啦!!!
通过asp.net怎么操作excel文件,我想把我生成的excel文件的某些列变成不是科学技术法的格式,例如201307051624263000而不是2.01307E+17
public static void Export(DataSet ds, Page ps, string title)
{
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
DateTime now = DateTime.Now;
string tmpSortDate = now.ToShortDateString();
Random Rnd = new Random(Environment.TickCount);
//string newname = title;
string newname = now.ToString("yyyyMMddHHmmss") + Rnd.Next(10000000, 99999999).ToString();
string m = HttpUtility.UrlEncode(newname, System.Text.Encoding.UTF8) + ".xls";
HttpResponse resp = ps.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.ContentType = "application/ms-excel";
resp.AppendHeader("Content-Disposition", "attachment;filename=" + m);
string colHeaders = "", ls_item = "";
DataTable dt = ds.Tables[0];
DataRow[] myRow = dt.Select();
int i = 0;
int cl = dt.Columns.Count;
int cols = cl - 1;//总列数,最后一列‘序号’不显示
for (i = 0; i < cols; i++)
{
if (i == (cols - 1))
{
colHeaders += dt.Columns[i].Caption.ToString() + "\n";
}
else
{
colHeaders += dt.Columns[i].Caption.ToString() + "\t";
}
}
resp.Write(colHeaders);
foreach (DataRow row in myRow)
{
for (i = 0; i < cols; i++)
{
string temp = row[i].ToString();
if (i == (cols - 1))
{
ls_item += " " + temp + "\n";
}
else
{
ls_item += " " + temp + "\t";
}
}
resp.Write(ls_item);
ls_item = "";
}
resp.End();
}
} Excel ASP.NET 技术 --------------------编程问答-------------------- 指定单元格为文字列 --------------------编程问答--------------------
dg.Cells[5].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");--------------------编程问答-------------------- 这边有你想要的答案。 --------------------编程问答-------------------- 可以在导出的数字字符前面加个单引号,使导出的内容变为文本格式 --------------------编程问答-------------------- foreach (DataRow row in myRow)
{
for (i = 0; i < cols; i++)
{
string temp = row[i].ToString() + " ";
if (i == (cols - 1))
{
ls_item += " " + temp + "\n";
}
else
{
ls_item += " " + temp + "\t";
}
}
resp.Write(ls_item);
ls_item = "";
}
补充:.NET技术 , ASP.NET