导出Excel后文本前面怎么去掉单引号’

超级小猪拱白菜 2010-11-26 04:51:19
如题:


代码

 GC.Collect();
Excel.Application excel = new Excel.ApplicationClass();
Excel._Workbook xBk;
Excel._Worksheet xSt;

xBk = excel.Workbooks.Add(true);
xSt = (Excel._Worksheet)xBk.ActiveSheet;
string xTitle = "";
int rowIndex; //行
int colIndex; //列
int colcnt; //列数
int rowcnt; //行数
int Mgcnt; //合并行数
object Cell1, Cell2; //合并范围

xSt.Cells.Font.Size = 10;
xSt.Cells.Font.Name = "宋体";
xSt.Cells.NumberFormatLocal = "@"; //文本格式
xSt.Rows.WrapText = true; //自动换行

colcnt = dt.Columns.Count;
rowIndex = 1;
colIndex = 1;
rowcnt = dt.Rows.Count;
for (int i = 0; i < colcnt; i++)
{
excel.Cells[rowIndex, i + 1] = "'" + dt.Columns[i].ColumnName;

}
xSt.get_Range(excel.Cells[1, 1], excel.Cells[1, Cells]).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenterAcrossSelection;
//行高
//xSt.get_Range(excel.Cells[1, 1], excel.Cells[1, Cells]).RowHeight = 40;
xSt.get_Range(excel.Cells[1, 1], excel.Cells[1, Cells]).Cells.Interior.ColorIndex = 40;
for (int i = 1; i <= Cells; i++)
{
//列宽度
xSt.get_Range(excel.Cells[1, i], excel.Cells[1, i]).ColumnWidth = CellWidth;// CellWidth[i - 1];
}
xSt.get_Range(excel.Cells[1, 1], excel.Cells[rowcnt + 1, Cells]).Borders.LineStyle = 1;
...全文
1461 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
是不是数字的?设置单元格属性为 数值,然后小数位数为0实验一下
孟子E章 2010-11-26
  • 打赏
  • 举报
回复
excel.Cells[rowIndex, i + 1] = dt.Columns[i].ColumnName;
  • 打赏
  • 举报
回复
大哥们 那个 不是我加上去的,就是Excel默认在文本前面加个单引号,我现在想知道怎么才能去掉它。谢谢哥哥们了!
caoleisu 2010-11-26
  • 打赏
  • 举报
回复
为什么要加‘呢,是不是导出来为科学技术法?
generhappy 2010-11-26
  • 打赏
  • 举报
回复
去掉‘
mayanly 2010-11-26
  • 打赏
  • 举报
回复
怎么加上去的怎么去掉。
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]
.Trim(''')
[/Quote]

在哪里.Trim(''');
  • 打赏
  • 举报
回复
到底要设置那个属性,或者设置什么东西才能不让那个单引号显示出来。
q107770540 2010-11-26
  • 打赏
  • 举报
回复
.Trim(''')

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧