C#操作EXCEL画表格的问题 我想问下 把一个字符串写入到了一个合并的了的 RANGE中 现在我想在这个RANGE中画表格 让这个字符串以表格的形式显示 怎么做??比如字符串是GGGJKHUIHU 我想画很多表格把让每个字母占一个表格 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你看这个方法行不行他是rang的方法你可以在这里http://download.csdn.net/source/614652下载到office 2003 vba的编程手册,里面有关于excel中rang对象的详细描述Table 方法请参阅 应用于 示例 特性 依据输入值和工作表上定义的公式创建数据表。expression.Table(RowInput, ColumnInput)expression 必需。该表达式返回“应用于”列表中的一个对象。RowInput Variant 类型,可选。用作数据表行输入的单个单元格。ColumnInput Variant 类型,可选。用作数据表列输入的单个单元格。说明使用数据表,通过更改工作表上特定常量的值,并观察其他单元格相应的变化情况,可进行假设分析。示例本示例在工作表 Sheet1 的 A1:K11 单元格中创建一个带格式的乘法运算表。Set dataTableRange = Worksheets("Sheet1").Range("A1:K11")Set rowInputCell = Worksheets("Sheet1").Range("A12")Set columnInputCell = Worksheets("Sheet1").Range("A13")Worksheets("Sheet1").Range("A1").Formula = "=A12*A13"For i = 2 To 11 Worksheets("Sheet1").Cells(i, 1) = i - 1 Worksheets("Sheet1").Cells(1, i) = i - 1Next idataTableRange.Table rowInputCell, columnInputCellWith Worksheets("Sheet1").Range("A1").CurrentRegion .Rows(1).Font.Bold = True .Columns(1).Font.Bold = True .Columns.AutoFitEnd With 随便录制了一个宏,如果是你需要的效果就按这种方式编程就行了,你可以复制到excel里面运行看看效果我觉得你要的效果可以这样做,先得到你的字符串,然后计算有多少字母,然后把你的rang的单元格平均分配给这些字母一个字母能够分到比如说2个单元格,那么你就每2个单元格合并成一个,然后将一个字母插入进入合并后的单元格,最后合并完成再去获取总的rang对象,当然出现分配单元格不是整数是你业务上解决的问题你自己根据需求自己解决Sub Macro1()'' Macro1 Macro' 宏由 roro 录制,时间: 2008-9-19'' Range("A1:G17").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With Selection.Borders(xlEdgeRight).LineStyle = xlNone Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$G$17"), , xlNo).Name = _ "列表1" Range("I7").Select ActiveSheet.ListObjects("列表1").Resize Range("$A$1:$A$18") Range("I6").Select Sheets("Sheet2").Select Range("A1:A2").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("A1:A2").Select ActiveCell.FormulaR1C1 = "f" Range("B1:B2").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge ActiveCell.FormulaR1C1 = "d" Range("A3:A4").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge ActiveCell.FormulaR1C1 = "a" Range("B3:B4").Select ActiveCell.FormulaR1C1 = "" Range("B3:B4").Select Range("B4").Activate With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge ActiveCell.FormulaR1C1 = "u" Range("A1:B4").Select ActiveWindow.SmallScroll Down:=-6 Range("B3:B4").Select Application.Goto Reference:="Macro1"End Sub 控制大小的问题解决了 有没有高手知道 在一个RANGE 中画了对角线以后 怎么样才能让写入的数据在对角线的两边 对于宏来说其实就是可以看成自动生成的vba代码,在vb里面的话就可以直接将这段代码copy进去修改一点点就能够运行了而对于我给你的宏你可以将他们复制到你的excel示例的宏命令中运行你在对office系列做vba编程的时候使用录制宏功能完成你要的需求,然后编辑宏模式下查看自动生成的宏转换成c#编程就行了很是方便对于如何单元格划线,我录制了下Sub Macro1()'' Macro1 Macro' 宏由 roro 录制,时间: 2008-9-22'' Range("A1").Select ActiveCell.FormulaR1C1 = "123" Range("A1").Select ActiveCell.FormulaR1C1 = "123 321" With ActiveCell.Characters(Start:=1, Length:=3).Font .Name = "宋体" .FontStyle = "常规" .Size = 12 .Strikethrough = False .Superscript = False .Subscript = True .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With With ActiveCell.Characters(Start:=4, Length:=1).Font .Name = "宋体" .FontStyle = "常规" .Size = 12 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With With ActiveCell.Characters(Start:=5, Length:=3).Font .Name = "宋体" .FontStyle = "常规" .Size = 12 .Strikethrough = False .Superscript = True .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("A1").Select With Selection.Borders(xlDiagonalDown) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone Selection.Borders(xlEdgeBottom).LineStyle = xlNone Selection.Borders(xlEdgeRight).LineStyle = xlNone Range("A1").SelectEnd Sub 如果你实在不会看宏就看下面的方法,你转换成c# vba编程http://zhidao.baidu.com/question/4311134.html?fr=qrl1.在单元格中输入斜线两端的文字 2.选斜线上文字-右键-设置单元格格式-特殊效果-上标; 3.选斜线下文字-右键--设置单元格格式-特殊效果-下标; 4.调整字的大小和位置, 5.设置单元格格式——边框里画对角线画上斜线 以上是分成两栏的,如果你想分三栏,画线的时候就不用设置单元格格式——边框里画对角线的方法了,用插入——图片——自选图形——直线的方法画,文字的话还是一个用上标,一个下标,一个正常,自己再调整一下大小位置,试试看 webpart的位置自动变,怎么回事 关于继承List<T>,Json序列化问题 EXT radiogroup FileExists报错问题,在线等!!!! C# 中获取外部程序中的TextBox ListView控件问题 高手们帮忙给点建议:多对一c/s结构网络通讯程序设计 "select * from a;select * from b "查询返回的ds.Fill(ds),如果确定ds中的表名 高手帮忙,如何定义字符串类型的三维数组.多谢!! 如何在DATAGRID中显示相关表内容? 妖怪问题,在线等 c#中关于判断是否存在模态对话框的问题?
你可以在这里http://download.csdn.net/source/614652
下载到office 2003 vba的编程手册,里面有关于excel中rang对象的详细描述Table 方法
请参阅 应用于 示例 特性
依据输入值和工作表上定义的公式创建数据表。expression.Table(RowInput, ColumnInput)expression 必需。该表达式返回“应用于”列表中的一个对象。RowInput Variant 类型,可选。用作数据表行输入的单个单元格。ColumnInput Variant 类型,可选。用作数据表列输入的单个单元格。说明
使用数据表,通过更改工作表上特定常量的值,并观察其他单元格相应的变化情况,可进行假设分析。示例
本示例在工作表 Sheet1 的 A1:K11 单元格中创建一个带格式的乘法运算表。Set dataTableRange = Worksheets("Sheet1").Range("A1:K11")
Set rowInputCell = Worksheets("Sheet1").Range("A12")
Set columnInputCell = Worksheets("Sheet1").Range("A13")Worksheets("Sheet1").Range("A1").Formula = "=A12*A13"
For i = 2 To 11
Worksheets("Sheet1").Cells(i, 1) = i - 1
Worksheets("Sheet1").Cells(1, i) = i - 1
Next i
dataTableRange.Table rowInputCell, columnInputCell
With Worksheets("Sheet1").Range("A1").CurrentRegion
.Rows(1).Font.Bold = True
.Columns(1).Font.Bold = True
.Columns.AutoFit
End With
我觉得你要的效果可以这样做,先得到你的字符串,然后计算有多少字母,然后把你的rang的单元格平均分配给这些字母一个字母能够分到比如说2个单元格,那么你就每2个单元格合并成一个,然后将一个字母插入进入合并后的单元格,最后合并完成
再去获取总的rang对象,当然出现分配单元格不是整数是你业务上解决的问题你自己根据需求自己解决
Sub Macro1()
'
' Macro1 Macro
' 宏由 roro 录制,时间: 2008-9-19
''
Range("A1:G17").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$G$17"), , xlNo).Name = _
"列表1"
Range("I7").Select
ActiveSheet.ListObjects("列表1").Resize Range("$A$1:$A$18")
Range("I6").Select
Sheets("Sheet2").Select
Range("A1:A2").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Range("A1:A2").Select
ActiveCell.FormulaR1C1 = "f"
Range("B1:B2").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "d"
Range("A3:A4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "a"
Range("B3:B4").Select
ActiveCell.FormulaR1C1 = ""
Range("B3:B4").Select
Range("B4").Activate
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "u"
Range("A1:B4").Select
ActiveWindow.SmallScroll Down:=-6
Range("B3:B4").Select
Application.Goto Reference:="Macro1"
End Sub
有没有高手知道 在一个RANGE 中画了对角线以后 怎么样才能让写入的数据在对角线的两边
而对于我给你的宏你可以将他们复制到你的excel示例的宏命令中运行
你在对office系列做vba编程的时候使用录制宏功能完成你要的需求,然后编辑宏模式下查看自动生成的宏转换成c#编程就行了很是方便
对于如何单元格划线,我录制了下
Sub Macro1()
'
' Macro1 Macro
' 宏由 roro 录制,时间: 2008-9-22
''
Range("A1").Select
ActiveCell.FormulaR1C1 = "123"
Range("A1").Select
ActiveCell.FormulaR1C1 = "123 321"
With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = True
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=4, Length:=1).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=5, Length:=3).Font
.Name = "宋体"
.FontStyle = "常规"
.Size = 12
.Strikethrough = False
.Superscript = True
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A1").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Range("A1").Select
End Sub
http://zhidao.baidu.com/question/4311134.html?fr=qrl
1.在单元格中输入斜线两端的文字
2.选斜线上文字-右键-设置单元格格式-特殊效果-上标;
3.选斜线下文字-右键--设置单元格格式-特殊效果-下标;
4.调整字的大小和位置,
5.设置单元格格式——边框里画对角线画上斜线 以上是分成两栏的,如果你想分三栏,画线的时候就不用设置单元格格式——边框里画对角线的方法了,用插入——图片——自选图形——直线的方法画,文字的话还是一个用上标,一个下标,一个正常,自己再调整一下大小位置,试试看