如何设置导出的EXCEL文件的列格式在office的EXCEL中我们可以在一个EXCEL文件中,选中一列再点击鼠标右键,选择设置单元格格式,可以将这一列设为文本格式等;请问各位,如果我想在导出EXCEL时在代码中实现这个将列的格式设置为文本格式的功能,要怎样做呢?那位能否帮下忙,------解决方案--------------------用excel组件导出 ------解决方案--------------------
//文本:vnd.ms-excel.numberformat:@ //日期:vnd.ms-excel.numberformat:yyyy/mm/dd //数字:vnd.ms-excel.numberformat::#,##0.00 //货币:vnd.ms-excel.numberformat¥#,##0.00 //百分比:vnd.ms-excel.numberformat:#0.00% //在excel中数字位数大于11位,都会默认以科学技术法出现,所以有E+. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { for(int i=0;i<e.Row.Cells.Count;i++) { if(e.Row.RowType==DataControlRowType.DataRow) { //表示对每一行以字符串的形式输出 e.Row.Cells[i].Attributes.Add("style","vnd.ms-excel.numberformat:@"); } } } //如果你想对导出的execl的某一行进行以字符串输出,而不想用科学计数法出现,则需要上面方法,最好对某一列以字符串输出,excel也是从0列开始的. ------解决方案-------------------- 设置单元格的文本 Excel.Application.get_Range(excelApp.Cells[x1, y1], excelApp.Cells[x2, y2]).NumberFormatLocal="@" ------解决方案--------------------mySheet.Cells(1,9).NumberFormatLocal = "@"Excel.Range r = mySheet.get_Range(mySheet.Cells[1, 1], mySheet.Cells[1,3]);r.NumberFormat = "@"; r.NumberForma = "0.00_ "r.NumberForma = "¥#,##0.00;¥-#,##0.00"r.NumberForma = _"_ ¥* #,##0.00_ ;_ ¥* -#,##0.00_ ;_ ¥* ""-""??_ ;_ @_ "r.NumberForma = "yyyy-m-d"r.NumberForma = "[$-F400]h:mm:ss AM/PM"r.NumberForma = "000000"myExcel.get_Range(myExcel.Cells[1, 1], myExcel.Cells[1, 1]).Font.Bold = true; myExcel.get_Range(myExcel.Cells[1,1],myExcel.Cells[1,1]).Font.Size = 16; ------解决方案--------------------dataTable 导出 ------解决方案--------------------//文本:vnd.ms-excel.numberformat:@//日期:vnd.ms-excel.numberformat:yyyy/mm/dd//数字:vnd.ms-excel.numberformat::#,##0.00//货币:vnd.ms-excel.numberformat¥#,##0.00//百分比:vnd.ms-excel.numberformat:#0.00%转载于:https://www.cnblogs.com/lihuiqi/p/11433097.html
相关资源:python操作openpyxl导出Excel 设置单元格格式及合并处理代码实例