15. 将以下程序直接加到上一段程序的后面,也是要在class Program 的closing bracket (}) 里面;为避免手工输入这些语句,可以通过插入代码段 | My Code Snippets | CalculateEmus.
private static void CalculateEmus(Bitmap bitmap, out int widthInEmu, out int heightInEmu)
{
float verticalResolution = bitmap.VerticalResolution;
float horizontalResolution = bitmap.HorizontalResolution;
int width = bitmap.Size.Width;
int height = bitmap.Size.Height;
float widthInInches = (float)width / horizontalResolution;
float heightInInches = (float)height / verticalResolution;
widthInEmu = (int)(widthInInches * 914400);
heightInEmu = (int)(heightInInches * 914400);
}
{
float verticalResolution = bitmap.VerticalResolution;
float horizontalResolution = bitmap.HorizontalResolution;
int width = bitmap.Size.Width;
int height = bitmap.Size.Height;
float widthInInches = (float)width / horizontalResolution;
float heightInInches = (float)height / verticalResolution;
widthInEmu = (int)(widthInInches * 914400);
heightInEmu = (int)(heightInInches * 914400);
}
备注:这个辅助程序将产品图像的高和宽转换成用emu作为单位的值。EMU是English metric Unit的缩写,被用于OpenXML的文档规范。至此所有程序代码已经添加完毕。
16. 将每个Method的代码隐藏起来,你的程序代码编辑窗口应该看上去像这样:

17. 现在编辑解决方案:在解决方案资源管理器中,右击项目CreateDocFromDatabase ,选中菜单选项生成。编辑应该通过无误。
18. 现在在运行程序之前我们要准备必须的文档:将文档Template.docx 从路径 c:\HOL\OFCHOL245\Resources\拷贝到c:\HOL\OFCHOL245\CreateDocFromDatabase\bin\Debug。可以通过以下几步完成:
·在Windows的任务栏(taskbar)中点击资源管理器图标打开资源管理器(从左边数第三个图标)

·在资源管理器中,在上方的路径中填入c:\HOL\OFCHOL245\Resources

·右击文档Template.docx,在菜单中选中复制。

·回到Visual Studio 2008,在解决方案资源管理器中,点击显示所有文件图标

·在解决方案资源管理器中,展开CreateDocFromDatabase | bin | Debug;右击Debug,在菜单中选择粘贴将Template.docx粘贴在bin\debug路径里。
