向我推荐用于生成打印预览和打印的解决方案 [英] Recommend me a solution for generating print preview and printing

查看:141
本文介绍了向我推荐用于生成打印预览和打印的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介和相关信息:

我正在维护一个旧的应用程序,我需要实现一个功能,该功能可以根据从数据库计算出的数据生成报告.用户还必须具有打印文件的其他选项(用户必须能够选择打印机,并且必须能够看到打印预览).

为了提高获得满意答案的机会,请允许我用一个小的示例"来进一步说明问题:

-用户按下按钮->应用程序计算数据; // Done

-应用程序创建文件并用结果填充它; // Done

-用户被告知已生成报告; // Done

-用户按下另一个为打印付费的按钮; // Stuck here!

-弹出打印预览,并提供一个运行打印对话框的选项. // Stuck here

-用户启动打印对话框,选择打印机,然后应用程序将打印文件;

使用原始WinAPI( no MFC)在C++中对应用程序进行编码.我正在研究Windows XP.

问题:

我能够成功使用OLE Automation生成/保存 Word和Excel 报告,但是我无法解决打印任务.

如果我使用OLE Automation来显示 Excel的打印对话框/打印预览,则可能会出现以下问题:

用户可以简单地单击关闭打印预览",也可以简单地关闭打印属性表返回文档,这可能会损害文档的数据.

因此,我需要一种用于保护用户数据的方式来为用户生成打印预览的解决方案.

此外,用户应该能够选择将打印文件的打印机.

问题:

注释:

问题范围太广,无法在一个帖子中回答,因此我只能限制自己寻求指导意见/一般概念/指向正确的方向.

实际问题:

我已尽力使用OLE Automation Excel/Word 文件,但是如您所见,生成打印预览存在问题,因此存在以下问题:

1.由于这是我第一次处理此类任务,您能推荐给我适当的处理方法(当然是一般概念)吗?

2.是否有解决我的打印问题的解决方法(例如将WM_PRINTCLIENT消息发送到 Word/Excel 或类似的东西)?

备注:

再次,我意识到这个问题太广泛了,所以只给我一些一般性的概念/指针,这样,如果我被困在某个地方,就可以发表单独的问题.

我不需要使用 Word/Excel OLE Automation,这是我目前的选择.

如果您可以推荐更好的解决方案,我将很乐意接受. 我不想使用库.

如果需要其他信息,请询问,我将编辑我的帖子.

INTRODUCTION AND RELEVANT INFORMATION:

I am maintaining an old application and I need to implement feature that generates reports based on data calculated from a database. User must also have an additional option of printing the file ( user must be able to choose printer, and must be able to see print preview ).

To improve my chances of getting satisfactory answer, allow me to additionally clarify matters with a small "example":

- User presses a button -> application calculates data; // Done

- Application creates file and populates it with the result; // Done

- User gets informed that report is generated; // Done

- User presses another button that is charged for printing; // Stuck here!

- Print preview pops up and an option to run print dialog. // Stuck here

- User starts the print dialog, chooses the printer and application prints the file;

The application is coded in C++ using raw WinAPI ( no MFC ). I am working on Windows XP.

PROBLEM:

I was able to successfully use OLE Automation to generate/save Word and Excel reports but I can not solve the printing task.

If I use OLE Automation to show Excel''s print dialog/print preview, there is a following problem that might occur :

User can simply click "Close Print Preview", or can simply close print property sheet and return to the document which might compromise document''s data.

Therefore, I need a solution for generating a print preview for the user, in a way that protects document data.

Furthermore, user should be able to choose the printer that will print the file.

QUESTION:

INTRODUCTORY NOTES:

The question is too broad to be answered in one post so I must limit myself only for seeking advice / general concept / pointing in the right direction.

THE ACTUAL QUESTIONS :

I did the best I could with the OLE Automation and Excel / Word files, but as you can see there are problems with generating a print preview, hence the following questions :

1. Since this is my first time to tackle this kind of task, can you recommend me the proper way to handle it ( general concepts of course )?

2. Is there a chance that there is a workaround for my printing problem ( like sending WM_PRINTCLIENT message to the Word / Excel or something like that )?

REMARKS :

Again, I realize the question is too broad so just give me general concepts / pointers, so I could post separate questions if I get stuck somewhere in the way.

I do not need to use Word / Excel and OLE Automation, it was my choice at the moment.

If you can recommend better solution I will gladly accept. I do not wish to use libraries.

If additional information is required, ask and I will edit my post.

推荐答案

Codeproject.com上已经存在一个非常好的解决方案.看到这个:

打印DataGridView [
A very nice solution already exists here at Codeproject.com. See this one:

Printing of DataGridView[^]


这篇关于向我推荐用于生成打印预览和打印的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆