编写课程以打开Word文档 [英] Writing a class to open a word doc

查看:106
本文介绍了编写课程以打开Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我花时间尝试执行此操作之前,我想征求第二意见.我正在编写一个应用程序,在其中,我需要在大约4个不同的位置(到目前为止)中打开一个word doc.因此,我不是想写4次相同的代码,而是想上课吗?我正在考虑将文件名照常传递给类和进程(所有错误处理现在都在循环中进行了处理).这听起来可行吗?软件.


是否可行取决于代码的运行状况.但是总的来说,是的,您不必在多个地方重复相同的代码.甚至两次都太多了.因此,提取执行此操作的类/静态方法肯定会有所改进.

在UI场景中,您甚至可能想要有一个自定义控件,该控件接受word文档路径并进行呈现.


Before I spend time trying to do this I''d like to get a second opinion. I''m writing an application and in it I need to open a word doc in about 4 different places (as of now). So instead of writing the same code 4 times I''m thinking a class would be the way to go? I''m thinking pass the file name to the class and process as normal (all of the error handling is taken care of in the loops right now). Does this sound feasible?

解决方案

Writing reusable code rather than cut & paste the same thing over and over again is a good design and what you should strive for in all your software.


Whether it is feasible depends on how well your code works. But in general, yes, you should not have to repeat the same code in multiple places. Even twice is too many. So extracting a class/static method that does this would certainly be an improvement.

In a UI scenario, you mght even want to have a custom control that accepts a word document path and renders it.


这篇关于编写课程以打开Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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