本帖最后由 zqckzqck 于 2014-10-09 00:19:02 编辑

解决方案 »

  1.   

    单位是EMU,1英寸= 914400 EMU
      

  2.   

    可是我设置了居左插入图片
     gp = m_Docx.CreateParagraph();
               gp.GetCTPPr().AddNewJc().val = ST_Jc.left;//居左对齐显示
                gr = gp.CreateRun();//创建run
                gfs = new FileStream(m_PicPath + "16.png", FileMode.Open, FileAccess.Read);//读取图片文件
                gr.SetTextPosition(0);
                gr.AddPicture(gfs, (int)PictureType.PNG, "16.png", 3000000, 500000);//插入图片
                //单位EMU 1英寸=914400EMU
                gfs.Close();
    但是打开word发现,虽然格式是居左可图片还是靠右的,就是ST_Jc.center效果还是靠右的。这是怎么回事啊?急,请大家帮忙分析分析
      

  3.   

    word文档中插入图片问题
    //选择文档保存位置
     private void btn_Select_Click(object sender, EventArgs e)
            {
                G_FolderBrowserDialog =//创建浏览文件夹对象
                  new FolderBrowserDialog();
                DialogResult P_DialogResult = //浏览文件夹
                    G_FolderBrowserDialog.ShowDialog();
                if (P_DialogResult == DialogResult.OK)//确认已经选择文件夹
                {
                    btn_New.Enabled = true;//启用新建按钮
                    txt_path.Text = //显示选择路径
                        G_FolderBrowserDialog.SelectedPath;
                }
            }
    //选择图片
     private void btn_Image_Click(object sender, EventArgs e)
            {
                G_OpenFileDialog =//创建浏览文件夹对象
                     new OpenFileDialog();
                DialogResult P_DialogResult = //浏览文件夹
                    G_OpenFileDialog.ShowDialog();
                if (P_DialogResult == DialogResult.OK)//确认已经选择文件夹
                {
                    txt_ImagePath.Text =//显示选择路径
                        G_OpenFileDialog.FileName;
                    btn_Select.Enabled = true;//启用浏览文档按钮
                    this.Width = 553;//设置窗体宽度
                    pbox_Image.Image = //显示图片
                        Image.FromFile(G_OpenFileDialog.FileName);
                }
            }//创建Word文档插入图片
    private void btn_New_Click(object sender, EventArgs e)
            {
                btn_New.Enabled = false;//停用新建按钮
                ThreadPool.QueueUserWorkItem(//使用线程池
                    (P_temp) =>//使用lambda表达式
                    {
                        G_wa = new Word.Application();//创建Word应用程序对象
                        Word.Document P_wd = G_wa.Documents.Add(//建立新文档
                            ref G_missing, ref G_missing, ref G_missing, ref G_missing);
                        Word.Range P_Range = P_wd.Paragraphs[1].Range;//得到段落范围
                        object P_Ranges = P_Range;//创建ojbect对象
                        P_wd.InlineShapes.AddPicture(//向文档中插入图片
                            G_OpenFileDialog.FileName, ref G_missing, ref G_missing, ref P_Ranges);
                        G_str_path = string.Format(//计算文件保存路径
                            @"{0}\{1}", G_FolderBrowserDialog.SelectedPath,
                            DateTime.Now.ToString("yyyy年M月d日h时s分m秒fff毫秒") + ".doc");
                        P_wd.SaveAs(//保存Word文件
                            ref G_str_path,
                            ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                            ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                            ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                            ref G_missing, ref G_missing, ref G_missing);
                        ((Word._Application)G_wa.Application).Quit(//退出应用程序
                            ref G_missing, ref G_missing, ref G_missing);
                        this.Invoke(//开始执行窗体线程
                            (MethodInvoker)(() =>//使用lambda表达式
                            {
                                btn_Display.Enabled = true;//启用显示按钮
                                MessageBox.Show("成功创建Word文档!", "提示!");
                            }));
                    });
            }
      

  4.   

    NPOI创建DOCX常用操作:http://blog.csdn.net/gltide/article/details/39929259