*– 程序说明:将一个包含有2层数据分组的表输出到EXCEL[/b]表里,并分组统计
*– 原创作者:红虎 于 2001年1月29日
*– 自定义函数:
* letter2num 将列字母转换成相应的数字顺序,传递字母,返回数字
* num2letter 将数字顺序转换成相应的列字母,传递数字,返回字母
* itmcls2name 将itmclass代码转成相应的名称
if messagebox(”在程序执行过程中,请耐性等待,直至程序运行完毕!”,1+48,”警告”) =2
retu
endif

*– 包含有VBA宏里的值[/b]的英文代码转换到VFP[/b]里相应的值[/b]
#include vb_marco.h
*– 创建 EXCEL[/b] 实例对象
oExcel = CreateObject(”excel[/b].application”)
*– 开始在 EXCEL[/b] 里添加数据 …
With oExcel
.visible = .T. && 可见
.Workbooks.Add && 增加一个工作薄
.Sheets(”Sheet1″).Select
.Sheets(”Sheet1″).Name = “sample” && 改变SHEET名称

.Application.WindowState = xlMaximized && 最大化 EXCEL[/b]
.Cells.Select && 全选工作簿
With .Selection.Font
.Name = “宋体”
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
EndWith
.range(”c1″) = “1999 年产品预算资料” && 显示报表标题
.Rows(”1:1″).RowHeight = 41.25
.Range(”c1:t1″).select && 选择报表标题
.Range(”c1:t1″).merge && 合并
With .Selection
.HorizontalAlignment= xlCenter
.VerticalAlignment = xlMedium
.Font.Bold = True
.Font.Size = 20
Endwith
.ActiveWindow.Zoom = 50 && 50%显示
*– 报表表格的表头,横向顺序显示
dime rpt_header(20)
rpt_header(1) = “类别”
rpt_header(2) = “组别”
rpt_header(3) = “产品名称”
rpt_header(4) = “单价”
rpt_header(5) = “单位”
rpt_header(6) = “生效日期”
rpt_header(7) = “一月份”
rpt_header(8) = “二月份”
rpt_header(9) = “三月份”
rpt_header(10) = “四月份”
rpt_header(11) = “五月份”
rpt_header(12) = “六月份”
rpt_header(13) = “七月份”
rpt_header(14) = “八月份”
rpt_header(15) = “九月份”
rpt_header(16) = “十月份”
rpt_header(17) = “十一月份”
rpt_header(18) = “十二月份”
rpt_header(19) = “数量合计”
rpt_header(20) = “金额合计”
*– 添加表头数据
for n=1 to 20
cn = num2letter(n)
.Range(”&cn.2″).select && 选择当前列的第 2 行
.Range(”&cn.2″) = rpt_header(n) && 填充数据
endfor
.Range(”d2,g2:t2″).Select
.Selection.HorizontalAlignment = xlRight && 居右对齐
*– 添加表中数据
dime datalist(18)
datalist(1) = “itmclass”
datalist(2) = “majcod”
datalist(3) = “allt(descrp1)”
datalist(4) = “price”
datalist(5) = “unitpkg”
datalist(6) = “pdate”
datalist(7) = “m01″
datalist(8) = “m02″
datalist(9) = “m03″
datalist(10) = “m04″
datalist(11) = “m05″
datalist(12) = “m06″
datalist(13) = “m07″
datalist(14) = “m08″
datalist(15) = “m09″
datalist(16) = “m10″
datalist(17) = “m11″
datalist(18) = “m12″
if !used(”sample_item”)
use sample_item in 0 share
endif
sele sample_item
count to nMaxRec && 计算这个表共有的记录数
i = 0
nStartLine = 3 && 数据从第三行开始
*– 对整个表进行从头到为的循环处理
scan
cnLine = allt(str(i+nStartLine)) && 当前数据的行号
for n=1 to 18 && 在一个记录中,对字段进行循环填充
Cell = num2letter(n)+cnLine && 当前需要填充数据的单元格
.Range(”&Cell”).Select && 选择该单元格
data = datalist(n)
.Range(”&Cell”) = &data
endfor
i = i + 1
endscan
*– 对数量合计进行填充,她等于 m01+m02+…+m12的合计
*– 对金额合计的填充则等于数量合计*单价
*– 数量合计在第19列,金额合计在第20列
*– 所以针对第一行进行加入公式,然后进行复制
cRow = allt(str(nStartLine))
cMaxRow = allt(str(nStartLine+i-1)) && 最后行的行数
.Range(”s&cRow”).Select && 选择第一行的合计数量单元格
.Range(”s&cRow”) = “=sum(g&cRow.:r&cRow)” && 加入计算她的合计数字的公式
.Range(”t&cRow”) = “= s&cRow * d&cRow” && 加入合计金额的计算公式
.Range(”s&cRow.:t&cRow”).Select && 选择合计金额
.Range(”s&cRow.:t&cRow”).Copy && 复制该两个选择的单元格
.Range(”s&cRow.:t&cMaxRow”).Select && 选择需要粘贴的单元格
.ActiveSheet.Paste && 粘贴所复制的两项
.Range(”g&cRow.:s&cMaxRow”).Select && 选择全部1-12月数字的区域
.Range(”g&cRow.:s&cMaxRow”).NumberFormatLocal = “#,##0_ ;[红色]-#,##0 ” && 选择数字区域的单元格,设置他们的格式
.Range(”s&cRow.:t&cMaxRow”).Select
With .Selection.Interior
.ColorIndex = 43
.Pattern = xlSolid
EndWith
*– 数据填充完毕,下面进行数据的分组
*– 分组由外面先分,即对itmclass分组,然后再对majcod进行分组
*– 而这个时候需要选择包括表头和所有数据在内的所有的区域
*– 在给ITMCLASS做数据分组时,只要选择从表头开始到最后行的数据即可,
* 可是在给MAJCOD继续做数据分组时,因第一次的分组而加入了分组数据,导致数据行已经增加了
* 因此需要重新计算去选择新的范围,而所加的内容的多少视具体分组情况而定
*– 分组统计
sele itmclass,majcod,majdsc from sample_item into cursor temp_source
sele recn() as rec_no,itmclass,majcod,majdsc from temp_source into cursor temp
nTotal1 = _tally && 原有记录
use in temp_source
sele * from temp group by itmclass into cursor temp_grp_itmclass
nTotal2 = nTotal1 + _tally + 1 && 加上类别分组后的数据行数
sele * from temp group by itmclass,majcod into cursor temp_grp_majcod
nTotal3 = nTotal2 + _tally + 1 && 加上组别分组后的数据行数
*- 产生一个同EXCEL[/b]里同样格式的表
create cursor cursor_excel[/b] ( ;
rec_no n (8) ,;
itmclass c (1) ,;
majcod c (3) ,;
majdsc c (30) )
i = 1
sele temp_grp_majcod
scan
*– 分组小计统计数据
sele cursor_excel[/b]
appe blank
repl rec_no with temp_grp_majcod.rec_no + nStartLine - 1 + i
repl itmclass with temp_grp_majcod.itmclass
repl majcod with temp_grp_majcod.majcod
repl majdsc with allt(temp_grp_majcod.majdsc) + ” 分组小计”
i = i + 1
sele temp_grp_itmclass
loca for rec_no = temp_grp_majcod.rec_no
if found()
*– 分类小计统计数据
sele cursor_excel[/b]
appe blank
repl rec_no with temp_grp_itmclass.rec_no + nStartLine - 1 + i
repl itmclass with temp_grp_itmclass.itmclass
repl majcod with temp_grp_itmclass.majcod
repl majdsc with itmcls2name(itmclass) + ” 生产线小计”
i = i + 1
endif
endscan
use in temp_grp_itmclass
use in temp_grp_majcod
use in temp
*– 添加两个总计行
sele cursor_excel[/b]
go bott
n = rec_no
appe blank
repl rec_no with n+1
repl majdsc with “最终合计”
appe blank
repl rec_no with n+2
repl majdsc with “最终合计”
*– 至此得到一个临时表cursor_excel[/b],
* 其字段rec_no所记录的数据与EXCEL[/b]表里通过两次分组再自动排序后的行号一致
* 这些信息可以用来改写分组的数据
*– 在EXCEL[/b]中对类别分组
* 开始行为 nStartLine -1 ,结束行为 nTotal1 + nStartLine -1 , 列A-T
cRow = allt(str(nStartLine-1))
cMaxRow = allt(str(nTotal1+nStartLine-1))
.Range(”A&cRow.:T&cMaxRow”).Select
.Range(”A&cRow.:T&cMaxRow”).SubTotal (1,xlSum,7,True,False,True) && 第7列为M01
*– 在EXCEL[/b]中对组别分组
* 开始行为 nStartLine -1 ,结束行为 nTotal2 + nStartLine -1 , 列A-T
cMaxRow = allt(str(nTotal2+nStartLine-1))
.Range(”A&cRow.:T&cMaxRow”).Select
.Range(”A&cRow.:T&cMaxRow”).SubTotal (2,xlSum,7,False,False,True) && 第7列为M01
*– 数据分组已经完成,对EXCEL[/b]表格再进行处理
*– 隐藏A、B两列,及隐藏最后一行
sele cursor_excel[/b]
go bott
cn = allt(str(rec_no))
.Columns(”A:B”).Select
.Selection.EntireColumn.Hidden = True
.Rows(”&cn.:&cn”).Select
.Selection.EntireRow.Hidden = True

*– 锁放屏幕到75%
.ActiveWindow.Zoom = 75
.Range(”c1″).select
.ActiveSheet.Outline.ShowLevels (3) && 选择分组层数第3
*– 重新改写分组数据
sele cursor_excel[/b]
scan
cn=allt(str(rec_no))
.Range(”c&cn”) = allt(majdsc)
.Range(”c&cn.:f&cn”).Select
with .Selection
.Merge
.HorizontalAlignment = xlRight
endwith
.Range(”g&cn”).copy
.Range(”h&cn.:t&cn”).select
.ActiveSheet.Paste
.Range(”c&cn.:t&cn”).font.bold = True
if right(allt(majdsc),10)=”生产线小计”
.Range(”C&cn.:t&cn”).Select
With .Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
EndWith
endif
endscan

.Range(”t:t”).NumberFormatLocal = “#,##0.00_ ;[红色]-#,##0.00 ” && 设置金额的格式为99,999.99
*– 画上表格线
* 开始行为 nStartLine -1 ,结束行为 nTotal3 + nStartLine -1 , 列A-T
cMaxRow = allt(str(nTotal3+nStartLine-1))
.Range(”A&cRow.:T&cMaxRow”).Select
with .Selection
*– 左边
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
*– 上边
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
*– 右边
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
*– 下边
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
*– 里边垂直
.Borders(xlInsideVertical[/b]).LineStyle = xlContinuous
.Borders(xlInsideVertical[/b]).Weight = xlThin
*– 里边水平
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).Weight = xlThin
endwith

*– 调整每列宽度
.ActiveWindow.Zoom = 100
for n=asc(’C') to asc(’T')
cn=allt(chr(n))
.columns(”&cn.:&cn”).entirecolumn.autofit
endfor

*– 打印设置,预览
.ActiveSheet.PageSetup.PrintArea = “”
With .ActiveSheet.PageSetup
.LeftHeader = “”
.CenterHeader = “”
.RightHeader = “”
.LeftFooter = “”
.CenterFooter = “”
.RightFooter = “”
.LeftMargin = .Application.InchesToPoints(0.75)
.RightMargin = .Application.InchesToPoints(0.75)
.TopMargin = .Application.InchesToPoints(1)
.BottomMargin = .Application.InchesToPoints(1)
.HeaderMargin = .Application.InchesToPoints(0.5)
.FooterMargin = .Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 180
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA3
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
EndWith
.ActiveSheet.Outline.ShowLevels (4) && 选择分组层数第4
.ActiveWindow.SelectedSheets.PrintPreview
Endwith
messagebox(”程序完成!”,64,”提示”)
*– 自定义函数
*– 将EXCEL[/b]里的列的字母从A-IV转换到相应的数字顺序
Func letter2num
*– 传递来的字母 , 字母会有两种情况,为,一个字母和二个字母
PARA cLetter
private num,cLetter1,cLetter2
num = 0
*– 如果传递来的参数不是字符,那么以默认为字母 A
if type(”cLetter”)#”C”
cLetter = “A”
endif
*– 转换为大写
cLetter = upper(cLetter)
*– 判断位数是否为2位
nLen = len(cLetter)
if nLen > 2 or nLen 256
messagebox(”最大只能到 IV 列,即 256 列!此时返回 256 !”,48,”错误”)
num = 256
endif
retu num

*– 将EXCEL[/b]里列的顺序号转换到相应的字母A-IV
Func num2letter
*– 传递来的数字列
para num
private letter,num1,num2
*– 如果传递来的参数不是数字型,以 1 为默认值[/b]
if type(”num”) # “N”
num = 1
endif
*– 判断
if num > 256 or num 0 && 表示有十位数
letter = chr(num1+64) + letter
endif
retu letter
*– 将itmclass代码转成相应的名称
Func ItmCls2Name
Para cItem_Class
if !cItem_class$”123456789″
retu “无”
endif
nItem_class=val(cItem_class)
dime cItmClsLst(9)
cItmClsLst(1) = “1 = 嘉顿饼”
cItmClsLst(2) = “2 = 糖”
cItmClsLst(3) = “3 = 包”
cItmClsLst(4) = “4 = 蛋糕”
cItmClsLst(5) = “5 = ??”
cItmClsLst(6) = “6 = ??”
cItmClsLst(7) = “7 = ??”
cItmClsLst(8) = “8 = 月饼”
cItmClsLst(9) = “9 = 利华饼”
retu cItmClsLst(nItem_Class)

*– 程序说明:将一个包含有2层数据分组的表输出到EXCEL[/b]表里,并分组统计
*– 原创作者:红虎 于 2001年1月29日
*– 自定义函数:
* letter2num 将列字母转换成相应的数字顺序,传递字母,返回数字
* num2letter 将数字顺序转换成相应的列字母,传递数字,返回字母
* itmcls2name 将itmclass代码转成相应的名称
if messagebox(”在程序执行过程中,请耐性等待,直至程序运行完毕!”,1+48,”警告”) =2
retu
endif

*– 包含有VBA宏里的值[/b]的英文代码转换到VFP[/b]里相应的值[/b]
#include vb_marco.h
*– 创建 EXCEL[/b] 实例对象
oExcel = CreateObject(”excel[/b].application”)
*– 开始在 EXCEL[/b] 里添加数据 …
With oExcel
.visible = .T. && 可见
.Workbooks.Add && 增加一个工作薄
.Sheets(”Sheet1″).Select
.Sheets(”Sheet1″).Name = “sample” && 改变SHEET名称

.Application.WindowState = xlMaximized && 最大化 EXCEL[/b]
.Cells.Select && 全选工作簿
With .Selection.Font
.Name = “宋体”
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
EndWith
.range(”c1″) = “1999 年产品预算资料” && 显示报表标题
.Rows(”1:1″).RowHeight = 41.25
.Range(”c1:t1″).select && 选择报表标题
.Range(”c1:t1″).merge && 合并
With .Selection
.HorizontalAlignment= xlCenter
.VerticalAlignment = xlMedium
.Font.Bold = True
.Font.Size = 20
Endwith
.ActiveWindow.Zoom = 50 && 50%显示
*– 报表表格的表头,横向顺序显示
dime rpt_header(20)
rpt_header(1) = “类别”
rpt_header(2) = “组别”
rpt_header(3) = “产品名称”
rpt_header(4) = “单价”
rpt_header(5) = “单位”
rpt_header(6) = “生效日期”
rpt_header(7) = “一月份”
rpt_header(8) = “二月份”
rpt_header(9) = “三月份”
rpt_header(10) = “四月份”
rpt_header(11) = “五月份”
rpt_header(12) = “六月份”
rpt_header(13) = “七月份”
rpt_header(14) = “八月份”
rpt_header(15) = “九月份”
rpt_header(16) = “十月份”
rpt_header(17) = “十一月份”
rpt_header(18) = “十二月份”
rpt_header(19) = “数量合计”
rpt_header(20) = “金额合计”
*– 添加表头数据
for n=1 to 20
cn = num2letter(n)
.Range(”&cn.2″).select && 选择当前列的第 2 行
.Range(”&cn.2″) = rpt_header(n) && 填充数据
endfor
.Range(”d2,g2:t2″).Select
.Selection.HorizontalAlignment = xlRight && 居右对齐
*– 添加表中数据
dime datalist(18)
datalist(1) = “itmclass”
datalist(2) = “majcod”
datalist(3) = “allt(descrp1)”
datalist(4) = “price”
datalist(5) = “unitpkg”
datalist(6) = “pdate”
datalist(7) = “m01″
datalist(8) = “m02″
datalist(9) = “m03″
datalist(10) = “m04″
datalist(11) = “m05″
datalist(12) = “m06″
datalist(13) = “m07″
datalist(14) = “m08″
datalist(15) = “m09″
datalist(16) = “m10″
datalist(17) = “m11″
datalist(18) = “m12″
if !used(”sample_item”)
use sample_item in 0 share
endif
sele sample_item
count to nMaxRec && 计算这个表共有的记录数
i = 0
nStartLine = 3 && 数据从第三行开始
*– 对整个表进行从头到为的循环处理
scan
cnLine = allt(str(i+nStartLine)) && 当前数据的行号
for n=1 to 18 && 在一个记录中,对字段进行循环填充
Cell = num2letter(n)+cnLine && 当前需要填充数据的单元格
.Range(”&Cell”).Select && 选择该单元格
data = datalist(n)
.Range(”&Cell”) = &data
endfor
i = i + 1
endscan
*– 对数量合计进行填充,她等于 m01+m02+…+m12的合计
*– 对金额合计的填充则等于数量合计*单价
*– 数量合计在第19列,金额合计在第20列
*– 所以针对第一行进行加入公式,然后进行复制
cRow = allt(str(nStartLine))
cMaxRow = allt(str(nStartLine+i-1)) && 最后行的行数
.Range(”s&cRow”).Select && 选择第一行的合计数量单元格
.Range(”s&cRow”) = “=sum(g&cRow.:r&cRow)” && 加入计算她的合计数字的公式
.Range(”t&cRow”) = “= s&cRow * d&cRow” && 加入合计金额的计算公式
.Range(”s&cRow.:t&cRow”).Select && 选择合计金额
.Range(”s&cRow.:t&cRow”).Copy && 复制该两个选择的单元格
.Range(”s&cRow.:t&cMaxRow”).Select && 选择需要粘贴的单元格
.ActiveSheet.Paste && 粘贴所复制的两项
.Range(”g&cRow.:s&cMaxRow”).Select && 选择全部1-12月数字的区域
.Range(”g&cRow.:s&cMaxRow”).NumberFormatLocal = “#,##0_ ;[红色]-#,##0 ” && 选择数字区域的单元格,设置他们的格式
.Range(”s&cRow.:t&cMaxRow”).Select
With .Selection.Interior
.ColorIndex = 43
.Pattern = xlSolid
EndWith
*– 数据填充完毕,下面进行数据的分组
*– 分组由外面先分,即对itmclass分组,然后再对majcod进行分组
*– 而这个时候需要选择包括表头和所有数据在内的所有的区域
*– 在给ITMCLASS做数据分组时,只要选择从表头开始到最后行的数据即可,
* 可是在给MAJCOD继续做数据分组时,因第一次的分组而加入了分组数据,导致数据行已经增加了
* 因此需要重新计算去选择新的范围,而所加的内容的多少视具体分组情况而定
*– 分组统计
sele itmclass,majcod,majdsc from sample_item into cursor temp_source
sele recn() as rec_no,itmclass,majcod,majdsc from temp_source into cursor temp
nTotal1 = _tally && 原有记录
use in temp_source
sele * from temp group by itmclass into cursor temp_grp_itmclass
nTotal2 = nTotal1 + _tally + 1 && 加上类别分组后的数据行数
sele * from temp group by itmclass,majcod into cursor temp_grp_majcod
nTotal3 = nTotal2 + _tally + 1 && 加上组别分组后的数据行数
*- 产生一个同EXCEL[/b]里同样格式的表
create cursor cursor_excel[/b] ( ;
rec_no n (8) ,;
itmclass c (1) ,;
majcod c (3) ,;
majdsc c (30) )
i = 1
sele temp_grp_majcod
scan
*– 分组小计统计数据
sele cursor_excel[/b]
appe blank
repl rec_no with temp_grp_majcod.rec_no + nStartLine - 1 + i
repl itmclass with temp_grp_majcod.itmclass
repl majcod with temp_grp_majcod.majcod
repl majdsc with allt(temp_grp_majcod.majdsc) + ” 分组小计”
i = i + 1
sele temp_grp_itmclass
loca for rec_no = temp_grp_majcod.rec_no
if found()
*– 分类小计统计数据
sele cursor_excel[/b]
appe blank
repl rec_no with temp_grp_itmclass.rec_no + nStartLine - 1 + i
repl itmclass with temp_grp_itmclass.itmclass
repl majcod with temp_grp_itmclass.majcod
repl majdsc with itmcls2name(itmclass) + ” 生产线小计”
i = i + 1
endif
endscan
use in temp_grp_itmclass
use in temp_grp_majcod
use in temp
*– 添加两个总计行
sele cursor_excel[/b]
go bott
n = rec_no
appe blank
repl rec_no with n+1
repl majdsc with “最终合计”
appe blank
repl rec_no with n+2
repl majdsc with “最终合计”
*– 至此得到一个临时表cursor_excel[/b],
* 其字段rec_no所记录的数据与EXCEL[/b]表里通过两次分组再自动排序后的行号一致
* 这些信息可以用来改写分组的数据
*– 在EXCEL[/b]中对类别分组
* 开始行为 nStartLine -1 ,结束行为 nTotal1 + nStartLine -1 , 列A-T
cRow = allt(str(nStartLine-1))
cMaxRow = allt(str(nTotal1+nStartLine-1))
.Range(”A&cRow.:T&cMaxRow”).Select
.Range(”A&cRow.:T&cMaxRow”).SubTotal (1,xlSum,7,True,False,True) && 第7列为M01
*– 在EXCEL[/b]中对组别分组
* 开始行为 nStartLine -1 ,结束行为 nTotal2 + nStartLine -1 , 列A-T
cMaxRow = allt(str(nTotal2+nStartLine-1))
.Range(”A&cRow.:T&cMaxRow”).Select
.Range(”A&cRow.:T&cMaxRow”).SubTotal (2,xlSum,7,False,False,True) && 第7列为M01
*– 数据分组已经完成,对EXCEL[/b]表格再进行处理
*– 隐藏A、B两列,及隐藏最后一行
sele cursor_excel[/b]
go bott
cn = allt(str(rec_no))
.Columns(”A:B”).Select
.Selection.EntireColumn.Hidden = True
.Rows(”&cn.:&cn”).Select
.Selection.EntireRow.Hidden = True

*– 锁放屏幕到75%
.ActiveWindow.Zoom = 75
.Range(”c1″).select
.ActiveSheet.Outline.ShowLevels (3) && 选择分组层数第3
*– 重新改写分组数据
sele cursor_excel[/b]
scan
cn=allt(str(rec_no))
.Range(”c&cn”) = allt(majdsc)
.Range(”c&cn.:f&cn”).Select
with .Selection
.Merge
.HorizontalAlignment = xlRight
endwith
.Range(”g&cn”).copy
.Range(”h&cn.:t&cn”).select
.ActiveSheet.Paste
.Range(”c&cn.:t&cn”).font.bold = True
if right(allt(majdsc),10)=”生产线小计”
.Range(”C&cn.:t&cn”).Select
With .Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
EndWith
endif
endscan

.Range(”t:t”).NumberFormatLocal = “#,##0.00_ ;[红色]-#,##0.00 ” && 设置金额的格式为99,999.99
*– 画上表格线
* 开始行为 nStartLine -1 ,结束行为 nTotal3 + nStartLine -1 , 列A-T
cMaxRow = allt(str(nTotal3+nStartLine-1))
.Range(”A&cRow.:T&cMaxRow”).Select
with .Selection
*– 左边
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
*– 上边
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
*– 右边
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
*– 下边
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
*– 里边垂直
.Borders(xlInsideVertical[/b]).LineStyle = xlContinuous
.Borders(xlInsideVertical[/b]).Weight = xlThin
*– 里边水平
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).Weight = xlThin
endwith

*– 调整每列宽度
.ActiveWindow.Zoom = 100
for n=asc(’C') to asc(’T')
cn=allt(chr(n))
.columns(”&cn.:&cn”).entirecolumn.autofit
endfor

*– 打印设置,预览
.ActiveSheet.PageSetup.PrintArea = “”
With .ActiveSheet.PageSetup
.LeftHeader = “”
.CenterHeader = “”
.RightHeader = “”
.LeftFooter = “”
.CenterFooter = “”
.RightFooter = “”
.LeftMargin = .Application.InchesToPoints(0.75)
.RightMargin = .Application.InchesToPoints(0.75)
.TopMargin = .Application.InchesToPoints(1)
.BottomMargin = .Application.InchesToPoints(1)
.HeaderMargin = .Application.InchesToPoints(0.5)
.FooterMargin = .Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 180
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA3
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
EndWith
.ActiveSheet.Outline.ShowLevels (4) && 选择分组层数第4
.ActiveWindow.SelectedSheets.PrintPreview
Endwith
messagebox(”程序完成!”,64,”提示”)
*– 自定义函数
*– 将EXCEL[/b]里的列的字母从A-IV转换到相应的数字顺序
Func letter2num
*– 传递来的字母 , 字母会有两种情况,为,一个字母和二个字母
PARA cLetter
private num,cLetter1,cLetter2
num = 0
*– 如果传递来的参数不是字符,那么以默认为字母 A
if type(”cLetter”)#”C”
cLetter = “A”
endif
*– 转换为大写
cLetter = upper(cLetter)
*– 判断位数是否为2位
nLen = len(cLetter)
if nLen > 2 or nLen 256
messagebox(”最大只能到 IV 列,即 256 列!此时返回 256 !”,48,”错误”)
num = 256
endif
retu num

*– 将EXCEL[/b]里列的顺序号转换到相应的字母A-IV
Func num2letter
*– 传递来的数字列
para num
private letter,num1,num2
*– 如果传递来的参数不是数字型,以 1 为默认值[/b]
if type(”num”) # “N”
num = 1
endif
*– 判断
if num > 256 or num 0 && 表示有十位数
letter = chr(num1+64) + letter
endif
retu letter
*– 将itmclass代码转成相应的名称
Func ItmCls2Name
Para cItem_Class
if !cItem_class$”123456789″
retu “无”
endif
nItem_class=val(cItem_class)
dime cItmClsLst(9)
cItmClsLst(1) = “1 = 嘉顿饼”
cItmClsLst(2) = “2 = 糖”
cItmClsLst(3) = “3 = 包”
cItmClsLst(4) = “4 = 蛋糕”
cItmClsLst(5) = “5 = ??”
cItmClsLst(6) = “6 = ??”
cItmClsLst(7) = “7 = ??”
cItmClsLst(8) = “8 = 月饼”
cItmClsLst(9) = “9 = 利华饼”
retu cItmClsLst(nItem_Class)

转载于:https://www.cnblogs.com/hylan/archive/2008/10/03/1303448.html

将一个包含有2层数据分组的表输出到EXCEL表里,并分组统计相关推荐

  1. Jasperreport_6.18的吐血记录四之分组交叉表

    承接上篇 第三章主要说了交叉表的简单使用以及列出了在交叉表制作过程中可能会遇到的实际场景,还有就是实际场景中出现的一些坑,为了方便演示所以案例数据比较简单,希望小伙伴们认真阅读,细节很多,各位伙伴多注 ...

  2. SAP MM初阶之包含有Service item的服务采购订单

    SAP MM初阶之包含有Service item的服务采购订单 1, 执行事务代码ME21N创建了如下的服务采购订单. 该服务采购订单的item detail里Services Tab里,维护了三个s ...

  3. linux下Makefile中包含有shared library动态链接库文件时候的简单例子

    如果不知道什么是makefile,可以首先看我的另一篇博客: linux下Makefile的简单例子及解释 http://www.cnblogs.com/lihaozy/archive/2012/08 ...

  4. 松下plc FP-XH写的4轴控制程序,其中两个轴做直线插补,已经在12台设备上稳定运行,程序文件包含有plc程序触摸屏程序

    松下plc FP-XH写的4轴控制程序,其中两个轴做直线插补,已经在12台设备上稳定运行,程序文件包含有plc程序触摸屏程序,设备电气图纸清单,还有设备的清晰运行视频,能够帮助你很好的理解程序运行流程 ...

  5. R语言使用car包的leveneTest函数实现非参数的方差齐性检验、检验各分组方差是否相同

    R语言使用car包的leveneTest函数实现非参数的方差齐性检验.检验各分组方差是否相同 目录 R语言使用car包的leveneTest函数实现非参数的方差齐性检验.检验各分组方差是否相同

  6. 4.python蓝桥杯模拟题 一个包含有2019个结点的有向图,最多包含多少条边?(不允许有重边)

    4.python蓝桥杯模拟题 一个包含有2019个结点的有向图,最多包含多少条边?(不允许有重边) 1.用n表示图中顶点的数目,e表示边或者弧的数目,则对于无向图来说,e的取值范围为0-(1/2)n( ...

  7. 将一个只含有大小写字母的字符串大写变成小写,小写变成大写后输出。

    如题.将一个只含有大小写字母的字符串大写变成小写,小写变成大写后输出. 输入一个有大写有小写的字符串,把字符串中的字符大小写反转输出 输入样例 1 AcDe 输出样例 1 aCdE c++代码如下 # ...

  8. R语言使用epiDisplay包的summ函数计算dataframe数据中的指定数据列在分组变量下的统计量(样本数、均值、中位数、标准差、最大值、最小值)、可视化一个按照分类变量绘制的有序点图

    R语言使用epiDisplay包的summ函数计算dataframe数据中的指定数据列在分组变量下的统计量(样本数.均值.中位数.标准差.最大值.最小值).可视化一个按照分类变量绘制的有序点图 目录

  9. R语言使用epiDisplay包的summ函数计算dataframe数据中的指定数据列在分组变量下的统计量、可视化一个按照分类变量绘制的有序点图(有序点图分析数值型变量的分布、密集趋势、异常值)

    R语言使用epiDisplay包的summ函数计算dataframe数据中的指定数据列在分组变量下的统计量.可视化一个按照分类变量绘制的有序点图(有序点图分析数值型变量的分布.密集趋势.异常值) 目录

最新文章

  1. php vendor 删除,yii2我删除了vendor目录,然后重新composer install composer update就不行了。。。...
  2. Forbid consumer 192.168.85.1 access service com.sharearn.dubbo.romote.TestService from registry
  3. 10.1引用数据类型的转换
  4. [转载]----linux系统工程师的前途在哪里?
  5. leetcode1233. 删除子文件夹
  6. php读取excel存入mysql数据库_PHP将Excel内容导入mysql数据库
  7. paip.php-gtk 桌面程序 helloworld总结
  8. 【Linux下载安装jdk8】
  9. 2020-11-10 oracle 数据库sql 之decode函数
  10. hadoop如何解除safemode-安全模式
  11. Android开发关于调用摄像头黑屏没反应的问题
  12. BitTorrent 原理简介
  13. 十进制转换八进制代码c语言,利用栈将十进制转换为八进制(C语言)
  14. Sonatype Nexus3 搭建私有仓库
  15. python函数做菜单_学不会的Python函数——函数小案例(名片管理器)
  16. SASS实现颜色卡动画
  17. 微商城系统是什么?可以分为哪几类?
  18. Android制造 FaceID [FaceNet + MobileNet]
  19. 1024程序员节神评整理,要笑死了哈哈
  20. linux下进程的管理,Linux下的进程之进程管理

热门文章

  1. 无法获得 VMCI 驱动程序的版本: 句柄无效。 驱动程序“vmci.sys”的版本不正确。请尝试重新安装 VMware Workstation。 开启模块 DevicePowerOn 的操作失败
  2. java集成hibernate_JavaWeb_(Spring框架)Spring整合Hibernate
  3. twitter finagle java_java搭建finagle(2)
  4. box-sizing属性
  5. python conf配置文件
  6. 数据库设计(关系型)
  7. RSA加密算法的简单案例
  8. 数据结构(Splay平衡树):COGS 339. [NOI2005] 维护数列
  9. Fabric 报错:java.lang.IllegalArgumentException: UserContext user‘s name missing.
  10. Android事件处理之处理键盘事件