/// <summary> /// 打开或创建word文档 /// </summary> /// <param name="editorName">编辑名称</param> /// <param name="docTempleteFile">模板文件地址</param> /// <param name="destDocFile">目标存储位置</param> public static void openOrCreateWord(string editorName, string docTempleteFile, string destDocFile) { if (File.Exists(destDocFile)) { try { System.Diagnostics.Process.Start(destDocFile); } catch (Exception ex) { MessageBox.Show("打开文档" + editorName + "失败!Ex:" + ex.ToString()); } } else { if (File.Exists(docTempleteFile) && File.Exists(destDocFile) == false) { try { File.Copy(docTempleteFile, destDocFile, true); } catch (Exception ex) { MessageBox.Show("写入文档" + editorName + "失败!Ex:" + ex.ToString()); } } else { try { Aspose.Words.WordDocument wd = new Aspose.Words.WordDocument(); wd.WordDoc.Save(destDocFile); } catch (Exception ex) { MessageBox.Show("写入文档" + editorName + "失败!Ex:" + ex.ToString()); } } try { System.Diagnostics.Process.Start(destDocFile); } catch (Exception ex) { MessageBox.Show("打开文档" + editorName + "失败!Ex:" + ex.ToString()); } } }
private void btnEditDest_Click(object sender, EventArgs e) { string tempFile = GetDestFilePath(); if (File.Exists(tempFile)) { try { System.Diagnostics.Process p = System.Diagnostics.Process.Start(tempFile); } catch (Exception ex) { MessageBox.Show("打开文档" + EditorName + "失败!Ex:" + ex.ToString()); } } else { try { Aspose.Words.WordDocument wd = new Aspose.Words.WordDocument(); wd.WordDoc.Save(tempFile); } catch (Exception ex) { MessageBox.Show("写入文档" + EditorName + "失败!Ex:" + ex.ToString()); } try { System.Diagnostics.Process p = System.Diagnostics.Process.Start(tempFile); } catch (Exception ex) { MessageBox.Show("打开文档" + EditorName + "失败!Ex:" + ex.ToString()); } } }