rt
解决方案 »
- C# 动态调用WebService 接口时如何动态进行SoapHeader 验证
- System.Net.Sockets.Socket 未标记为可序列化
- webservice 小问题 在线等 解决问题100分 来着有分
- 高效分页存储过程,进来喝杯茶呀,呵呵
- c# 如何等待 Process.Start()结束啊? 求助
- 为什么我的WinForm程序没有配置文件?
- 保存问题 。。。。。。。。
- DataGrid中新增输入问题
- 有很高参考价值财务进销存早期版本源码分享(30M完全C#) 需要者发送邮件到[email protected] 每信必复
- SqlConnection timeout问题
- wpf中datacontext????
- 请问如果将yyyyMMddHHmmss格式的字符串转换成DateTime?
class opertateWord
{
public string contentText = "";
public void WordToPdf(string sourcePath)
{
object paramMissing = Type.Missing;
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word._Document wordDocument = null;
try
{
object paramSourceDocPath = sourcePath;
wordDocument = wordApplication.Documents.Open(
ref paramSourceDocPath,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing,
ref paramMissing);
string text;
if (wordDocument != null)
{
text = wordDocument.Content.Text;//这里只取word文本,要取其它内容也可以在这里选择。
contentText = text;
}
} catch (Exception e)
{
Console.WriteLine("错误提示:" + e.Message);
} finally
{
if (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
wordDocument = null;
}
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
wordApplication = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
#region 读取 /// <summary>
/// 读取一段
/// </summary>
/// <param name="ParaCount">/第几段</param>
/// <param name="ReadOnly">/是否只读</param>
/// <returns></returns>
public string Read(int ParaCount, bool ReadOnly)
{ string txt = Convert.ToString(MyDoc.Paragraphs[ParaCount].Range.Text);
return txt; }
/// <summary>
/// 读取指定长度
/// </summary>
/// <param name="Start">/开始位置</param>
/// <param name="End">/结束位置</param>
/// <returns></returns>
public string Read(int Start, int End)
{ object start = Start;
object end = End;
string txt = "";
txt = Convert.ToString(MyDoc.Range(ref start, ref end).Text);
return txt;
}
#endregion
#region 表相关操作
/// <summary>
/// 读取表的位置
/// </summary>
/// <param name="TableIndex">/哪个表</param>
public Word.Range TableLocation(int TableIndex)
{ MyRange = MyDoc.Tables[TableIndex].Range;
return MyRange;
}
/// <summary>
/// 当前文档内有几个表
/// </summary>
/// <returns></returns>
public int TableCount()
{
return MyDoc.Tables.Count;
}
/// <summary>
/// 返回一个表的内容
/// </summary>
/// <param name="TableIndex">/哪个表</param>
/// <returns></returns>
public Word.Table Read(int TableIndex)
{
return MyDoc.Tables[TableIndex];
}
#endregion