我做过把dbgrid里的数据导到excel中,不过现在找不到源码.
下面是在asp中把数据导到excel中,你看看有没有参考价值
只要把这些代码保存在文本文件中,后缀改为.htm,然后双击运行,就会打开excel程序
往里面灌数据.(前提是你的机器装了excel)
<html>
<body>
<script language="vbscript">
Dim xlApp, xlBook, xlSheet1
Dim mystr,nowrow
on error resume next
Set xlApp = CreateObject("Excel.Application"
if xlApp=Empty then
window.open "help.asp","ddd","width=400,HEIGHT=510,screenY=20,scrolly=true"
end if
Set xlBook = xlApp.Workbooks.Add
Set xlSheet1 = xlBook.Worksheets(1)
xlSheet1.Application.Visible = True
With xlBook.Styles("Normal"
.Font
.Name = "宋体"
.Size = 12
.Bold = False
.Italic = False
.Strikethrough = False
.ColorIndex = 1
End With
xlBook.Styles("Normal"
.HorizontalAlignment = 2
xlApp.Selection.Style = "Normal"
xlSheet1.Range("A1:Q1"
.Merge
xlSheet1.cells(1,1).value ="演示报表"
xlApp.Rows("1:1"
.RowHeight = 85
xlSheet1.cells(1,1).font.name="隶书"
xlSheet1.cells(1,1).font.size=25
xlSheet1.cells(1,1).HorizontalAlignment=3
xlSheet1.Range("A2:Q2"
.Merge
xlSheet1.cells(2,1).value ="库存商品明细表"
xlApp.Rows("2:2"
.RowHeight = 24
xlSheet1.cells(2,1).font.name="隶书"
xlSheet1.cells(2,1).font.size=25
xlSheet1.cells(2,1).HorizontalAlignment=3
nowrow=2
mystr="A"
&
nowrow &
":Q"
&
nowrow
xlSheet1.Range(mystr).Merge
mystr=nowrow &
":"
&
nowrow
xlApp.Rows(mystr).RowHeight = 40
nowrow = nowrow+1
mystr="A"
&
nowrow &
":C"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,1).value ="货主:"
&
"abc"
xlSheet1.cells(nowrow,1).HorizontalAlignment=2
mystr="D"
&
nowrow &
":H"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,4).value ="仓间:"
&
"asd"
xlSheet1.cells(nowrow,4).HorizontalAlignment=2
mystr="L"
&
nowrow &
":N"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,12).value ="起始日期:"
&
"sdf"
xlSheet1.cells(nowrow,12).HorizontalAlignment=4
mystr="O"
&
nowrow &
":Q"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,15).value ="截止日期:"
&
"dcv"
xlSheet1.cells(nowrow,15).HorizontalAlignment=4
nowrow = nowrow+1
mystr="A"
&
nowrow &
":A"
&
nowrow+1
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,1).value ="入出库单号"
mystr="B"
&
nowrow &
":B"
&
nowrow+1
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,2).value ="原始凭证号"
mystr="C"
&
nowrow &
":C"
&
nowrow+1
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,3).value ="送提货单位"
mystr="D"
&
nowrow &
"
"
&
nowrow+1
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,4).value ="库房"
mystr="E"
&
nowrow &
":E"
&
nowrow+1
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,5).value ="库位"
mystr="F"
&
nowrow &
":H"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,6).value ="上月结存"
xlSheet1.cells(nowrow+1,6).value ="件数"
xlSheet1.cells(nowrow+1,7).value ="数量"
xlSheet1.cells(nowrow+1,8).value ="层级数量"
mystr="I"
&
nowrow &
":K"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,9).value ="本月进仓"
xlSheet1.cells(nowrow+1,9).value ="件数"
xlSheet1.cells(nowrow+1,10).value ="数量"
xlSheet1.cells(nowrow+1,11).value ="层级数量"
mystr="L"
&
nowrow &
":N"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,12).value ="本月出仓"
xlSheet1.cells(nowrow+1,12).value ="件数"
xlSheet1.cells(nowrow+1,13).value ="数量"
xlSheet1.cells(nowrow+1,14).value ="层级数量"
mystr="O"
&
nowrow &
":Q"
&
nowrow
xlSheet1.Range(mystr).Merge
xlSheet1.cells(nowrow,15).value ="本月结存"
xlSheet1.cells(nowrow+1,15).value ="件数"
xlSheet1.cells(nowrow+1,16).value ="数量"
xlSheet1.cells(nowrow+1,17).value ="层级数量"
mystr=nowrow &
":"
&
nowrow+1
xlSheet1.Rows(mystr).HorizontalAlignment = 3
xlSheet1.Rows(mystr).VerticalAlignment = 2
nowrow = nowrow+2
mystr="A"
&
nowrow &
":Q"
&
nowrow
xlSheet1.range(mystr).value=array("a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11","a12","a13","a14","a15","a16","a17"
nowrow = nowrow+1
xlSheet1.cells(nowrow,1).value ="合计"
xlSheet1.cells(nowrow,6).value =11
xlSheet1.cells(nowrow,7).value =22
xlSheet1.cells(nowrow,8).value =33
xlSheet1.cells(nowrow,9).value =44
xlSheet1.cells(nowrow,10).value =55
xlSheet1.cells(nowrow,11).value =66
xlSheet1.cells(nowrow,12).value =77
xlSheet1.cells(nowrow,13).value =88
xlSheet1.cells(nowrow,14).value =99
xlSheet1.cells(nowrow,15).value =111
xlSheet1.cells(nowrow,16).value =222
xlSheet1.cells(nowrow,17).value =333
xlSheet1.Columns("A:Q"
.EntireColumn.AutoFit
</script>
asdf
</body>
</html>