using Aspose;
private void btn_Click(object sender, EventArgs e)
{
OpenFileDialog OFD = new OpenFileDialog();
if (OFD.ShowDialog() == DialogResult.OK)
{
Aspose.Words.Document doc = new Aspose.Words.Document(OFD.FileName);
if (doc != null)
{
//拷贝到桌面
string fileName = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\" + Path.GetFileNameWithoutExtension(OFD.FileName) + " - 复件" + Path.GetExtension(textBox1.Text);
if(!File.Exists(fileName))
{
File.Create(fileName).Close(); //创建后必须关闭,不然会资源占用
}
Aspose.Words.Document destinationDoc = doc.Clone();
if(Path.GetExtension(OFD.FileName) == ".doc")
{
destinationDoc.Save(fileName, Aspose.Words.SaveFormat.Doc);
}
else if (Path.GetExtension(OFD.FileName) == ".docx")
{
destinationDoc.Save(fileName, Aspose.Words.SaveFormat.Docx);
}
MessageBox.Show("拷贝成功!", "结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
C# Aspose拷贝Word
猜你喜欢
转载自blog.csdn.net/qq_35106907/article/details/84656392
今日推荐
周排行