用C#操作excel,如何绘制单元格格式 本帖最后由 kj86345580 于 2014-04-15 17:25:26 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Excel中录制一个宏,然后照着样子在你的程序中写。 貌似用这个Range 可以实现 就是range属性众多,不知道具体该怎么用 我录了一个宏,宏代码如下:Range("A2:L2").Select Application.WindowState = xlMinimized Application.WindowState = xlNormal Range("A2:L2").Select ActiveCell.FormulaR1C1 = _ "华洪珠宝首饰有限公司客户产品出货单" & Chr(10) & "送货单位:润邦迈李饰品 NO:55094 2013.12.10" With ActiveCell.Characters(Start:=1, Length:=0).Font .Name = "宋体" .FontStyle = "加粗" .Size = 22 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16777216 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With ActiveCell.Characters(Start:=1, Length:=17).Font .Name = "宋体" .FontStyle = "加粗" .Size = 14 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16777216 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With ActiveCell.Characters(Start:=18, Length:=6).Font .Name = "宋体" .FontStyle = "加粗" .Size = 22 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16777216 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With ActiveCell.Characters(Start:=24, Length:=7).Font .Name = "宋体" .FontStyle = "加粗" .Size = 22 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16776961 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With With ActiveCell.Characters(Start:=31, Length:=30).Font .Name = "宋体" .FontStyle = "加粗" .Size = 22 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .Color = -16777216 .TintAndShade = 0 .ThemeFont = xlThemeFontNone End With Range("G6").SelectEnd Sub但是完全不知道怎么照样写,求指导一下,就我说的效果,帮我写一个例子!万分感谢!! 就是range属性众多,不知道具体该怎么用额,这个你google下就知道了啊。自己看 就是range属性众多,不知道具体该怎么用额,这个你google下就知道了啊。自己看这个我知道,这种方法是把单元格作为一个整体来进行操作的,比如加粗会把整个单元格的所有文字加粗,但我现在要的是把单元格内指定的某个字加粗而已··· 录制完宏,还懒得研究人家excel产生的代码,这就没救了。 我是web的,用npoi,先创建excel,再创建格式 HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.CreateSheet(strFileNamet); try { #region 创建标题行及其相关的样式 HSSFRow titleRow = sheet.CreateRow(0); titleRow.HeightInPoints = 30; //行高 titleRow.CreateCell(0).SetCellValue(strHeaderText);//标题名 HSSFCellStyle titleCellStyle = workbook.CreateCellStyle(); //标题单元格样式 //标题字体样式 HSSFFont titleFont = workbook.CreateFont(); titleFont.FontName = "宋体"; titleFont.FontHeightInPoints = 22; titleFont.Boldweight = 700; //设置标题行的样式 titleCellStyle.SetFont(titleFont); titleCellStyle.Alignment = CellHorizontalAlignment.CENTER; titleCellStyle.VerticalAlignment = CellVerticalAlignment.CENTER; titleRow.GetCell(0).CellStyle = titleCellStyle; sheet.AddMergedRegion(new Region(0, 0, 0, 10));//合并 #endregion RegularExpressionValidator正则失灵了 关于treeview控件的更新问题 透明文件加密 为什么我的TCP服务端总是占用CPU100%??? 如何用C#打开WINDOWS自带的计算器? 更新问题,请哥哥姐姐们帮忙,谢谢了 关于自定义控件的问题 我是个C盲,谁能帮我解释一下到底什么是C#?(回答有分) 怎么把一个字符串转化成ASCII码? C#判断十几个文本框的输入哪些有数据 objectdatasource 的 SelectMethod 中如何读取 master page 中下拉框的值 如何用C#实现tiff文件的CCITT Group4压缩
Range("A2:L2").Select
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
Range("A2:L2").Select
ActiveCell.FormulaR1C1 = _
"华洪珠宝首饰有限公司客户产品出货单" & Chr(10) & "送货单位:润邦迈李饰品 NO:55094 2013.12.10"
With ActiveCell.Characters(Start:=1, Length:=0).Font
.Name = "宋体"
.FontStyle = "加粗"
.Size = 22
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=1, Length:=17).Font
.Name = "宋体"
.FontStyle = "加粗"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=18, Length:=6).Font
.Name = "宋体"
.FontStyle = "加粗"
.Size = 22
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=24, Length:=7).Font
.Name = "宋体"
.FontStyle = "加粗"
.Size = 22
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16776961
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With ActiveCell.Characters(Start:=31, Length:=30).Font
.Name = "宋体"
.FontStyle = "加粗"
.Size = 22
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("G6").Select
End Sub
但是完全不知道怎么照样写,求指导一下,就我说的效果,帮我写一个例子!万分感谢!!
自己看
自己看
这个我知道,这种方法是把单元格作为一个整体来进行操作的,比如加粗会把整个单元格的所有文字加粗,但我现在要的是把单元格内指定的某个字加粗而已···
HSSFSheet sheet = workbook.CreateSheet(strFileNamet);
try
{
#region 创建标题行及其相关的样式
HSSFRow titleRow = sheet.CreateRow(0);
titleRow.HeightInPoints = 30; //行高
titleRow.CreateCell(0).SetCellValue(strHeaderText);//标题名
HSSFCellStyle titleCellStyle = workbook.CreateCellStyle(); //标题单元格样式
//标题字体样式
HSSFFont titleFont = workbook.CreateFont();
titleFont.FontName = "宋体";
titleFont.FontHeightInPoints = 22;
titleFont.Boldweight = 700;
//设置标题行的样式
titleCellStyle.SetFont(titleFont);
titleCellStyle.Alignment = CellHorizontalAlignment.CENTER;
titleCellStyle.VerticalAlignment = CellVerticalAlignment.CENTER;
titleRow.GetCell(0).CellStyle = titleCellStyle;
sheet.AddMergedRegion(new Region(0, 0, 0, 10));//合并
#endregion