【恳求提点方法思路,商业供应也行】打印预览能实现EXCEL的那种打印效果。 及delphi与VBA.请详细指教,复制网址也可以。(300)

  • 主题发起人 主题发起人 周海涛
  • 开始时间 开始时间

周海涛

Unregistered / Unconfirmed
GUEST, unregistred user!
前期用FastReport 做的报表。出现问题;第一:报表预览后导出EXCEL的文件,打开一看表格全乱了,FastReport 自动增加了许多的列和行虽然打印出来的效果一样,到时导出的表格可用性很差。第二:怎样用做好的EXCEL格式(模板),将已经查询好的dataset装载到EXCEL中实现打印预览并可以打印,并可以导出数据。要能实现在原程序中打开,不要新打开一个EXCEL程序中窗口。第三:是否可以用OLEcontaner 在Delphi中一个Form中显示Excel ,并实现打印预览。不能再启动EXCEL本身执行打印预览。还有OLE创建了EXCEL对象后,有没有具体的控制OLE的方法
 
可以啊excel模板就可以的
 
直接作个模板就行了,不是.xlt模板文件哈,就是一个.xls文件。 xlApp1:=CreateOleObject( 'Excel.Application' );
book1:=xlApp1.Workbooks.Add(Excel模板文件名);
Sheet1:=Book1.ActiveSheet;
然后就写入数据吧,写完之后显示 xlApp1.Visible:=True;
 
哎,要是没有装Excel上面就出不来了,呵呵,其实Delphi一直都提供了一个控件 F1Book,自带的,呵呵,试用方法在本BBS里面辛苦你找找了,挺多的,呵呵!
 
dev express中的cxspreadsheet就可以 1、设计好xls的模板,然后导入就可以。2、可以导出xls。可以打印!
 
关注中,感谢高手提供思路与方法
 
用 Try V := createoleobject('excel.application') ;
Except Application.MessageBox( '系统没有安装Excel' , '提示信息' , MB_OK ) ;
Exit ;
End ;
wbk := V.workbooks.open( MainPath + 'D' + S ) ;
V.visible := True ;打开生产的EXCEL,
 
[:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:(][:D][:D][:D][:D][:D][:D][:D][:D][:D][:D][:D][:D][:D][:D][:D][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][:(!][^][^][^][^][^][^][^][^][:)][:)][:)][:)][:)][:)][:)][:)][:)][:)][:)][:)][:)]
 
是大周吗
 
问题已经解决,解决思路1、在delphi中放置EHlib控件,利用EHLIB的导出函数导出,数据较快。2、编写EXCEL模板,在面板里面写好VBA编码,3、在Delphi中编写函数 var excelobj, excelbook: variant;
applicationpath, runcommand, reportds, savefilename, excelpath: string;
Outresult: boolean;
begin
//---判断是否配置了数据源 [2009-1016添加判断] if trim(edit1.Text) = '' then
begin
application.MessageBox('提示', '系统管理员未设置导出报表数据源', 1 + 64);
abort;
end;
//--程序的路径 applicationpath := extractfilepath(Application.ExeName) + 'Excel/';
reportds := edit1.Text;
excelpath := applicationpath + reportds + '_module.xls';
//--判断模板文件是否存在 //--调用保存对话框 if EXCELSAVEDIA.Execute then
begin
savefilename := EXCELSAVEDIA.FileName end else
abort;
//--保存 SaveDBGridEhToExportFile(TDBGridEhExportAsXLS, EXCEL1, applicationpath + reportds + '.xls', True);
//--执行宏 excelobj := createoleobject('excel.application');
excelbook := excelobj.application.workbooks.add;
runcommand := reportds + '_module.xls!reportout';
try excelbook := excelobj.application.workbooks.open(excelpath);
//----把参数赋值给新建的EXCEL 工资本 excelbook.WorkSheets[2].Activate;
excelbook.WorkSheets[2].Cells[10, 1].Value := savefilename;
excelbook.WorkSheets[2].Cells[11, 1].Value := reportds;
excelbook.WorkSheets[2].Cells[12, 1].Value := applicationpath;
excelobj.application.run(runcommand);
excelbook.close(false);
except end;
//退出 excelobj.quit;
//--释放 excelobj := unassigned;
excelobj := unassigned;
application.MessageBox('导出成功', '提示', MB_OK);6、执行VBA后程序搞定贴上VBA的代码Sub Reportout() '''公用模块 begin
Dim savefilename As String '处理好文件的存储位置 Dim reportDS As String '报表数据源的编号 Dim applicationpath As String '程序的位置 Dim outexcelpath As String '程序Grid表格导出的位置 Dim lastrow As Integer Dim lastcolumn As Integer '限制第一个工作簿为MODULE1 第二个为 sheet1 Sheets("Sheet1").Select savefilename = Range("A10").Text reportDS = Range("A11").Text applicationpath = Range("A12").Text outexcelpath = Range("A12").Text & reportDS & ".xls" Sheets("Module1").Select Workbooks.Open filename:=outexcelpath '公用模块 END '选择并删除不需要的列 [手工设置 1、不需要的列] Range("A:A,B:B,C:C,G:G,H:H,K:K,L:L,M:M,O:O,Q:Q,R:R,S:S").Select Selection.Delete Shift:=xlToLeft '插入列 Columns("A:A").Select Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove '设置序号 Range("A2").Select ActiveCell.FormulaR1C1 = "1" Range("A3").Select ActiveCell.FormulaR1C1 = "2" Range("A2:A3").Select lastrow = ActiveSheet.UsedRange.Rows.Count If lastrow > 2 then
'2009-10-14调整 判断当行数小于2时候的报错 Selection.AutoFill Destination:=Range(Cells(2, 1), Cells(lastrow, 1)) End If '插入行 'Rows("1:1").Select 'Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 'Rows("1:1").Select 'Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove 'Range("A1").Select '计算表头行数和列数 Windows(reportDS & "_module.xls").Activate Sheets("Module1").Select '{[手工设置表头的大小] } '2009-10-15调整成动态判断 lastrow = ActiveSheet.UsedRange.Rows.Count lastcolumn = ActiveSheet.UsedRange.Rows.Column '插入行 Windows(reportDS & ".xls").Activate Dim k As Integer k = 1 do
Range("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove k = k + 1 Loop Until k > lastrow '复制来源 Windows(reportDS & "_module.xls").Activate Range(Cells(1, 1), Cells(lastrow, lastcolumn)).Select Selection.Copy '粘贴 Windows(reportDS & ".xls").Activate Range("A1").Select ActiveSheet.Paste Rows("3:3").Select Application.CutCopyMode = False Selection.Delete Shift:=xlUp '列宽自动 Columns("A:A").EntireColumn.AutoFit Columns("B:B").EntireColumn.AutoFit Columns("E:E").EntireColumn.AutoFit Columns("F:F").EntireColumn.AutoFit Columns("G:G").EntireColumn.AutoFit Columns("H:H").EntireColumn.AutoFit Columns("I:I").EntireColumn.AutoFit Columns("J:J").EntireColumn.AutoFit Columns("B:B").ColumnWidth = 25 '设置标题 Range("A1:J1").Select Range("A1:J1").RowHeight = 40 Range("A2:J2").RowHeight = 25 ActiveCell.FormulaR1C1 = "(" & Year(Date) & "年" & Month(Date) & "月" & Day(Date) & "日) 成车库收发存报表" '设置分组 lastrow = ActiveSheet.UsedRange.Rows.Count Dim grouprange As Range Set grouprange = Range(Cells(2, 1), Cells(lastrow, 10)) grouprange.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(5, 6, 7, 8, _ 9, 10), Replace:=True, PageBreaks:=False, SummaryBelowData:=True '设置分组的颜色 lastrow = ActiveSheet.UsedRange.Rows.Count Dim i As Integer i = 3 do
If Cells(i, 1) = "" then
Range(Cells(i, 1), Cells(i, 10)).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent2 .TintAndShade = 0.799981688894314 .PatternTintAndShade = 0 End With End If i = i + 1 Loop Until i = lastrow '设置格式 Dim myrange As Range Dim myborders As Borders Set myrange = Range(Cells(3, 1), Cells(lastrow, 10)) Set myborders = myrange.Borders myborders.LineStyle = xlDouble myrange.Select myrange.Borders(xlDiagonalDown).LineStyle = xlNone myrange.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .Color = -10477568 .TintAndShade = 0 .Weight = xlThick End With With Selection.Borders(xlEdgeTop) .LineStyle = xlDashDotDot .Color = -10477568 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Color = -10477568 .TintAndShade = 0 .Weight = xlThick End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .Color = -10477568 .TintAndShade = 0 .Weight = xlThick End With With Selection.Borders(xlInsideVertical) .LineStyle = xlDashDotDot .ThemeColor = 4 .TintAndShade = 0.599963377788629 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlDashDotDot .ThemeColor = 4 .TintAndShade = 0.599963377788629 .Weight = xlThin End With '保存工作表 ActiveWorkbook.Application.DisplayAlerts = False ActiveWorkbook.SaveAs filename:=savefilename, _ FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False End Sub
 
Delphi世界qq群:23981160喜欢d的都来
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部