我以前做过类似的项目 但是我们做的是将word转成一个个pdf 然后合并pdf的 不知道你需要吗? 需要的话我帮你找找源码
解决方案 »
- 花费我一天时间的问题(DataGridViewComboBoxColumn)
- WINFORM编译问题
- 用C#怎么实现广告创建时,可以绑定用户,广告到期后,系统发送到会员的站内短信和E-mail
- 动态加载的用户控件Click事件不触发
- C#实现window上传?
- 如何用C#编程实现在Excel中插入行和列,超急!!!在线等!!!
- (来的都给分)c#打印问题 。做过的朋友进来出出主意。
- 请高手帮忙,用C#编的应用程序中怎能实现背景几首音乐循环播放?
- 各位老大,关于连接sqlserver的问题,严重了
- 请高手指点:关于.net的CrystalReportViewer控件不能用的问题……
- 程序在运行过程中会异常退出
- VS2012连接ACCESS数据库问题
如果不是代码实现的话,都是使用Adobe Acrobat X 进行word和pdf互相转换,并实现pdf合并的。
代码实现,可能也可以使用Adobe Acrobat X 提供的库。
如果不是代码实现的话,都是使用Adobe Acrobat X 进行word和pdf互相转换,并实现pdf合并的。
代码实现,可能也可以使用Adobe Acrobat X 提供的库。
谢谢夸奖 嘿嘿
{
var app = new word.Application();
var doc = app.Documents.Add();
forea(var d in files)
{
app.Selection.InsertFile(d.FullName);
app.Selection.InsertBreak(word.WdBreakType.wdPageBreak);
};
doc.SaveAs2(FileName: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "合并结果.docx"));
doc.Close();
app.Quit();
}输出pdf,这也是上述doc的固有的SaveAs功能中的一项。这里就不给你写了。如果要进行比较专业的Office二次开发(而不是极其简单的个别操作),希望你好好研习Office的官方的组件和对象的使用方法,先不去纠结什么“第三方”组件。
//选择合并文档的保存位置开始合并Word文档
private Word.Application G_wa;//定义Word应用程序
private object G_missing = //定义G_missing字段并添加引用
System.Reflection.Missing.Value;
private OpenFileDialog G_OpenFileDialog;//定义打开文件对话框
private SaveFileDialog G_SaveFileDialog;//定义保存文件对话框
private List<string> G_Str_Files = new List<string>();//定义字符串集合 private void btn_split_Click(object sender, EventArgs e)
{
btn_Merge.Enabled = false;//停用合并按钮
ThreadPool.QueueUserWorkItem(//开始线程池
(pp) =>//使用lambda表达式
{
G_wa = new Microsoft.Office.Interop.Word.Application();//创建应用程序对象
Word.Document P_MainDocument =//新建合并文档对象
G_wa.Documents.Add(ref G_missing, ref G_missing
, ref G_missing, ref G_missing);
foreach (string P_Str in G_Str_Files)//遍历文档的集合
{
object P_strs = P_Str;//创建object对象
Word.Document P_Document = G_wa.Documents.Open(//打开Word文档
ref P_strs, 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 o);
Word.Range P_Range_temp = //得到文档全部范围
P_Document.Range(ref G_missing, ref G_missing);
P_Range_temp.Select();//选择文档全部范围
P_Range_temp.Copy();//复制文档全部范围
Word.Range P_Range_temp2 =//得到文档的范围
P_MainDocument.Range(ref G_missing, ref G_missing);
object P_end= Word.WdCollapseDirection.wdCollapseEnd;//创建object对象
P_Range_temp2.Collapse(ref P_end);//折叠文档范围
P_Range_temp2.Select();//选择档的最后位置
P_Range_temp2.Paste();//粘贴文档内容
((Word._Document)P_Document).Close(ref G_missing, ref G_missing,//关闭文档
ref G_missing);
}
object P_SavePath=G_SaveFileDialog.FileName;//创建object对象
P_MainDocument.SaveAs(//保存合并后的文档
ref P_SavePath, 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);//CodeGo.net/
((Word._Application)G_wa.Application).Quit(//退出应用程序
ref G_missing, ref G_missing, ref G_missing);
this.Invoke(//调用窗体线程
(MethodInvoker)(() =>//使用lambda表达式
{
Clipboard.Clear();//清空剪切板
MessageBox.Show(//提示已经创建Word
"成功合并Word文档!", "提示!");
btn_Merge.Enabled = true;//启用合并按钮
}));
});
}
//创建文件对话框对象
private void txt_select_Click(object sender, EventArgs e)
{
G_OpenFileDialog
= new OpenFileDialog();
G_OpenFileDialog.Filter = //筛选文件
"*.doc|*.doc";
DialogResult P_DialogResult =//打开文件对话框
G_OpenFileDialog.ShowDialog();
if (P_DialogResult == DialogResult.OK)//确认已经选择文件
{
lb_FileCollection.Items.Add(G_OpenFileDialog.FileName);
G_Str_Files.Add(G_OpenFileDialog.FileName);
btn_Save.Enabled = true;
txt_path.Text = //显示将要打开的文件
G_OpenFileDialog.FileName;
}
}
//创建保存文件对话框对象
private void btn_Save_Click(object sender, EventArgs e)
{
G_SaveFileDialog =
new SaveFileDialog();
G_SaveFileDialog.Filter = "*.doc|*.doc";
DialogResult P_DialogResult = //打开保存文件对话框
G_SaveFileDialog.ShowDialog();
if (P_DialogResult == DialogResult.OK)//判断是否保存文件
{
btn_Merge.Enabled = true;//启用合并按钮
txt_SavePath.Text = //显示保存文件路径
G_SaveFileDialog.FileName;
}
}
//Load two documents
//Load Document1 and Document2
Document DocOne = new Document();
DocOne.LoadFromFile(@"E:\Work\Document\welcome.docx", FileFormat.Docx);
Document DocTwo = new Document();
DocTwo.LoadFromFile(@"E:\Work\Document\New Zealand.docx", FileFormat.Docx);
//Merge
foreach (Section sec in DocTwo.Sections)
{
DocOne.Sections.Add(sec.Clone());
}
//Save and Launch
DocOne.SaveToFile("Merge.docx", FileFormat.Docx);详细参考: http://blog.csdn.net/eiceblue/article/details/43668671