当前位置:编程学习 > C#/ASP.NET >>

C#中如何将含有文字、图片或表格的二进制数据写入到word文档的书签位置

目前已经实现了通过在word文档中设置书签,在程序中将文字写入到该书签位置,用的是range.text
但如果现在的内容里包含了文字和图片或者是表格,那该怎么将这些内容都写到这个书签位置呢??? --------------------编程问答-------------------- 没有人做过这样的需求吗 --------------------编程问答--------------------

private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            if (of.ShowDialog() == DialogResult.OK)
            {
                byte[] bt = wordConvertByte(of.FileName);
                string ss = ByTeConvertWord(bt, "QQ1");
                label1.Text = ss;
            }
        }

        /// <summary>
        /// 创建word
        /// </summary>
        /// <param name="data"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public string ByTeConvertWord(byte[] data, string fileName)
        {
            string savaPath = @"\SystemWord\" + DateTime.Now.Ticks.ToString() + @"\";
            if (!System.IO.Directory.Exists(GetPath() + savaPath))
            {
                Directory.CreateDirectory(GetPath() + savaPath);
            }
            string filepath = GetPath() + savaPath + fileName + ".doc";
            FileStream fs;
            if (System.IO.File.Exists(filepath))
            {
                fs = new FileStream(filepath, FileMode.Truncate);
            }
            else
            {
                fs = new FileStream(filepath, FileMode.CreateNew);
            }
            BinaryWriter br = new BinaryWriter(fs);
            br.Write(data, 0, data.Length);
            br.Close();
            fs.Close();
            return filepath;
        }
/// <summary>
/// 读取word转化成进制
/// </summary>
/// <param name="wordpath"></param>
/// <returns></returns>
        private byte[] wordConvertByte(string wordpath)
        {
            byte[] byContent = null;
            System.IO.FileStream fs = null;
            System.IO.BinaryReader br = null;
            try
            {
                fs = new FileStream(wordpath, System.IO.FileMode.Open);
            }
            catch
            {

            }
            br = new BinaryReader((Stream)fs);
            byContent = br.ReadBytes((Int32)fs.Length);
            return byContent;
        }


        private string GetPath()
        {
            return Application.StartupPath;
        }

--------------------编程问答-------------------- 谢谢zyloveyrf的回复,但我不是要另存成一个word文件,而是现在已经有一个word文件了,我要在这个word文件中的书签位置插入哪些二进制数据。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,