C#中如何将含有文字、图片或表格的二进制数据写入到word文档的书签位置
目前已经实现了通过在word文档中设置书签,在程序中将文字写入到该书签位置,用的是range.text但如果现在的内容里包含了文字和图片或者是表格,那该怎么将这些内容都写到这个书签位置呢??? --------------------编程问答-------------------- 没有人做过这样的需求吗 --------------------编程问答--------------------
--------------------编程问答-------------------- 谢谢zyloveyrf的回复,但我不是要另存成一个word文件,而是现在已经有一个word文件了,我要在这个word文件中的书签位置插入哪些二进制数据。
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;
}
补充:.NET技术 , C#