我现在要把word文档给读取出来,必须要原样输出,比如文档里有表格,必须输出的也是表格。。求高手帮忙,希望有源码,提供信息者又分。。拜托大家了
解决方案 »
- 请各位大侠解释下这是为什么?
- 请教泛型基础知识
- 初学c#一个排序问题
- 如何提取网页内容?
- .net 编写的程序,打包后安装,安装後在有VS2005环境下可以运行,只有FRAMEWORK2.0环境下出错的问题
- ********** 一个简单却比较急的问题 ,asp.net datagrid 绑定 dataset。 问题解决马上给分。
- 页面提交前DropDownList会自动选择为第一项...急呀...
- 请问我用ajax传到页面一个list集合要怎么绑定到页面?然后设置里面显示数据等
- 大家有没有下面的源码?
- 菜鸟问题!!C#开发的软件 我想知道怎么才可以让别人用?
- c#如何给视频添加水印
- C#做的LocalSystem服务无法访问HKEY_CURRENT_USER问题
object file=path;
object nullobj=System.Reflection.Missing.Value;
Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data=Clipboard.GetDataObject();
string str=data.GetData(DataFormats.Text).ToString();
doc.Close();
HTML格式正则获取
{
public WordClass()
{
m_WordApp = new ApplicationClass();
}
#region 属性
public int WordCount
{
get
{
if (m_Document != null)
{
Range rng = m_Document.Content;
rng.Select();
return m_Document.Characters.Count;
}
else
return -1;
}
}
public object Missing
{
get
{
return missing;
}
}
#endregion
#region 基本任务
#region CreateDocument
public void CreateDocument(string template)
{
object obj_template = template;
if (template.Length <= 0) obj_template = missing;
m_Document = m_WordApp.Documents.Add(ref obj_template, ref missing, ref missing, ref missing);
}
public void CreateDocument()
{
this.CreateDocument("");
}
#endregion
#region OpenDocument
public void OpenDocument(string fileName, bool readOnly)
{
object obj_FileName = fileName;
object obj_ReadOnly = readOnly;
m_Document = m_WordApp.Documents.Open(ref obj_FileName, ref missing, ref obj_ReadOnly, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
}
public void OpenDocument(string fileName)
{
this.OpenDocument(fileName, false);
}
#endregion
#region Save & SaveAs
public void Save()
{
if (m_Document != null)
m_Document.Save();
}
public void SaveAs(string fileName)
{
object obj_FileName = fileName;
if (m_Document != null)
{
m_Document.SaveAs(ref obj_FileName, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
}
}
#endregion
#region Close
public void Close(bool isSaveChanges)
{
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
if (isSaveChanges)
saveChanges = WdSaveOptions.wdSaveChanges;
if (m_Document != null)
m_Document.Close(ref saveChanges, ref missing, ref missing);
}
#endregion
#region 文档中的文本和对象
public void AppendText(string text)
{
Selection currentSelection = this.m_WordApp.Selection;
// Store the user's current Overtype selection
bool userOvertype = this.m_WordApp.Options.Overtype;
// Make sure Overtype is turned off.
if (this.m_WordApp.Options.Overtype)
{
this.m_WordApp.Options.Overtype = false;
}
// Test to see if selection is an insertion point.
if (currentSelection.Type == WdSelectionType.wdSelectionIP)
{
currentSelection.TypeText(text);
currentSelection.TypeParagraph();
}
else
if (currentSelection.Type == WdSelectionType.wdSelectionNormal)
{
// Move to start of selection.
if (this.m_WordApp.Options.ReplaceSelection)
{
object direction = WdCollapseDirection.wdCollapseStart;
currentSelection.Collapse(ref direction);
}
currentSelection.TypeText(text);
currentSelection.TypeParagraph();
}
else
{
// Do nothing.
}
// Restore the user's Overtype selection
this.m_WordApp.Options.Overtype = userOvertype;
}
#endregion
#region 搜索和替换文档中的文本
public void Replace(string oriText, string replaceText)
{
object replaceAll = WdReplace.wdReplaceAll;
this.m_WordApp.Selection.Find.ClearFormatting();
this.m_WordApp.Selection.Find.Text = oriText;
this.m_WordApp.Selection.Find.Replacement.ClearFormatting();
this.m_WordApp.Selection.Find.Replacement.Text = replaceText;
this.m_WordApp.Selection.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);
} #endregion
#region 文档中的Word表格
/// <summary>
/// 向文档中插入表格
/// </summary>
/// <param name="startIndex">开始位置</param>
/// <param name="endIndex">结束位置</param>
/// <param name="rowCount">行数</param>
/// <param name="columnCount">列数</param>
/// <returns></returns>
public Table AppendTable(int startIndex, int endIndex, int rowCount, int columnCount)
{
object start = startIndex;
object end = endIndex;
Range tableLocation = this.m_Document.Range(ref start, ref end);
return this.m_Document.Tables.Add(tableLocation, rowCount, columnCount, ref missing, ref missing);
}
/// <summary>
/// 添加行
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public Row AppendRow(Table table)
{
object row = table.Rows[1];
return table.Rows.Add(ref row);
}
/// <summary>
/// 添加列
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public Column AppendColumn(Table table)
{
object column = table.Columns[1];
return table.Columns.Add(ref column);
}
/// <summary>
/// 设置单元格的文本和对齐方式
/// </summary>
/// <param name="cell">单元格</param>
/// <param name="text">文本</param>
/// <param name="align">对齐方式</param>
public void SetCellText(Cell cell, string text, WdParagraphAlignment align)
{
cell.Range.Text = text;
cell.Range.ParagraphFormat.Alignment = align;
}
#endregion
#region IDisposable 成员
public void Dispose()
{
try
{
if (m_WordApp != null)
m_WordApp.Quit(ref missing, ref missing, ref missing);
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
}
#endregion
}
}