在Excel中只格式化1列以强制文本,并将所有其他文件保存为数字,同时从asp.net导出到Excel
我必须下载一个有10列的Excel文件,在Excel中,我将70696918000007视为“7.06969E + 13”,在添加时,一切都正常显示
sbResponseString.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"> <head><style> td {mso-number-format:"\@";} </style><meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\"><!--[if gte mso 9]> <xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + worksheet_name + "</x:Name><x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head> <body>");
但我不想将所有其他列作为文本,因为我必须find其他列的总和。 所以如何格式化只有1列的Excel文本
这非常简单,我只是添加一个类到我想要转换为string的列
DataGrid dataExportExcel = new DataGrid(); dataExportExcel.DataSource = ds.Tables[0]; dataExportExcel.DataBind(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { dataExportExcel.Items[i].Cells[5].Attributes.Add("class", "Invoice") }
然后改变了代码
sbResponseString.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"> <head><style> .Invoice {mso-number-format:\'@'}</style><meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\"><!--[if gte mso 9]> <xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>" + worksheet_name + "</x:Name><x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head> <body>");
简单地为发票类添加单独的样式
- 从Excel导入到SQL Server中的特定列
- 无法findpath的Excel错误的一部分
- 如何避免在C#,ASP.NET中更改单元格的背景后,删除Excel表格的网格线颜色(默认浅灰色)?
- 是否有可能从Excel文件中读取数据,而无需将其上传到VB.Net中的服务器?
- 从.NET代码中导出Excel数据时,引发了“System.OutOfMemoryException”
- 从没有保存到文件系统的上传的Excel文件获取数据
- 工作簿不在MsWord中打开,并要求修复和修复后显示xml错误
- Vb.net出口gridview到Excel
- 在ASP.NET中的Web服务器上填写excel电子表格比interop更好的方法?