如何用c#对excel中的单元格进行设置(急!!!)

cool0929 2006-08-23 05:42:47
请问如何用c#对excel中的单元格格式进行设置,比如加边框,左右对齐等等
...全文
334 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cool0929 2006-08-23
  • 打赏
  • 举报
回复
dlzhangln(哎呀!哎呀!哎呀呀呀呀呀!这是啥造型啊?) 这位大哥你说的偶好像没看懂耶
dlzhangln 2006-08-23
  • 打赏
  • 举报
回复
看孟子e章的blog,有楼主要的例子,好像是做了一个关于汽车的表,你找找
cool0929 2006-08-23
  • 打赏
  • 举报
回复
必须对range进行操作吗?不能对单元格吗? 比如,cell(1,1)
gggjjj 2006-08-23
  • 打赏
  • 举报
回复
学习自己录宏,然后改成C#代码,一切都可搞定。
livode 2006-08-23
  • 打赏
  • 举报
回复
合并a1到f1并居中:

range = excel.get_Range("A1:F1",Type.Missing);
range.Select();
range.Font.Bold = true;
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//居中
range.VerticalAlignment = Excel.XlVAlign.xlVAlignBottom;
range.WrapText = false;
range.Orientation = 0;
range.AddIndent = false;
range.ShrinkToFit = false;
range.MergeCells = false;
range.Merge(Type.Missing);
cool0929 2006-08-23
  • 打赏
  • 举报
回复
好长啊,有没有简单的办法啊?
livode 2006-08-23
  • 打赏
  • 举报
回复
///画线
string cell = "A"+k.ToString()+":"+((char)(j+63)).ToString()+(i-1).ToString();
Excel.Range range = excel.get_Range(cell,Type.Missing);
range.Select();
Excel.Borders borders=range.Borders;
borders[Excel.XlBordersIndex.xlDiagonalDown].LineStyle = Excel.XlLineStyle.xlLineStyleNone;
borders[Excel.XlBordersIndex.xlDiagonalUp].LineStyle = Excel.XlLineStyle.xlLineStyleNone;

borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeLeft].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;

borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeTop].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeTop].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;

borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeBottom].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;

borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlEdgeRight].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;

borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;

borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous;
borders[Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin;
borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex= Excel.XlColorIndex.xlColorIndexAutomatic;
///画线结束

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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