关于VB6.0中使用Spread COM 8.0导出EXCEL插入标题时,如果邦定的数据库字段为Int类型时,标题中的中文自动变成了0,怎么回事?
1.数据库数据显示是通过如下方法从数据库中直接查询得到的:
- '设置数据源
- Set Rs = New ADODB.Recordset
- Rs.Open "SELECT ID,MDCode,PTCode,FACode,TSCode,OHCode,Q1Code,Q2Code,Q3Code,Source,UserName,FailType,PCName,Result,convert(varchar(20),StartTime,120),convert(varchar(20),EndTime,120),SysVER,Edition,Remark,SortID,CardType,DBase,CheckDBase,Xml,Equipment,convert(varchar(20),TSDate,120),convert(varchar(20),GLDate,120),CaInt,convert(varchar(20),LfDate,120) FROM TestTable where " & lstr, Ronn, adOpenKeyset, adLockOptimistic
- Set fpSpread1.DataSource = Rs
- Rs.Close
复制代码
2.表格数据显示如下图所示
3.我在导出EXCEL时,为了能够将标题一起导出,使用了如下方法:
先在第一行插入一行,然后将标题行的信息复制到刚插入的行,通过ExportToExcel方法导出后,再删除刚插入的行,具体代码如下:
- fpSpread1.Redraw = False
- fpSpread1.MaxRows = fpSpread1.MaxRows + 1
- fpSpread1.InsertRows 1, 1
- fpSpread1.Col = 1
- fpSpread1.col2 = fpSpread1.MaxCols
- fpSpread1.Row = 1
- fpSpread1.row2 = 1
-
- fpSpread1.BlockMode = True
- fpSpread1.CellType = CellTypeStaticText
- fpSpread1.BlockMode = False
- fpSpread1.CopyRange 1, -1000, fpSpread1.MaxCols, -1000, 1, 1
- fpSpread1.BlockMode = True
- fpSpread1.TypeHAlign = TypeHAlignCenter
- fpSpread1.BackColor = &H80FF80
- fpSpread1.ForeColor = &HFFFFFF
- fpSpread1.FontName = "Arial"
- fpSpread1.FontSize = 11
- fpSpread1.BlockMode = False
-
- ret = fpSpread1.ExportToExcel(dlg.FileName, "报表数据", "")
- '删除导出临时标题行
-
- fpSpread1.DeleteRows 1, 1
- fpSpread1.MaxRows = fpSpread1.MaxRows - 1
- fpSpread1.Redraw = True
复制代码
但是为什么我导出后的EXCEL文件中,只要数据库字段不是字符串类型的,标题名都没有正常显示。如下图所示:
如何解决啊!急急急
|
|