本文整理汇总了C#中Microsoft.Office.Interop.Word.Application类的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.Application类的具体用法?C# Microsoft.Office.Interop.Word.Application怎么用?C# Microsoft.Office.Interop.Word.Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Microsoft.Office.Interop.Word.Application类属于命名空间,在下文中一共展示了Microsoft.Office.Interop.Word.Application类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: print
/*Setting up a printable invoice for the required Customer
*/
public void print()
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Add("E:/CarRentalSystem/Invoice.docx");
doc.Variables["Name"].Value = lbl_Forename.Text + " " + lbl_Surname.Text;
doc.Variables["Address"].Value = lbl_Address.Text;
doc.Variables["Town"].Value = lbl_Town.Text;
doc.Variables["County"].Value = lbl_County.Text;
doc.Variables["Phone_No"].Value = lbl_Phone.Text;
doc.Variables["Date"].Value = lbl_Date.Text;
doc.Variables["Balance"].Value = lbl_Acc_Balance.Text;
doc.Variables["Id"].Value = lbl_Customer_Id.Text;
doc.Fields.Update();
doc.SaveAs2("E:/CarRentalSystem/Invoice.docx2");
doc.PrintOut();
doc.Close();
app.Quit();
}
开发者ID:pafennell,项目名称:SoftwareEngineering,代码行数:33,代码来源:IncomeAnalysis.cs
示例2: PrintReport
public void PrintReport()
{
Microsoft.Office.Interop.Word.Application oWord;
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
string activePrinter = oWord.ActivePrinter;
if (string.IsNullOrEmpty(this.m_PrinterName) == false)
{
oWord.ActivePrinter = m_PrinterName;
}
Object oFile = this.m_ReportSaveFileName;
Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Open(ref oFile, ref oMissing, ref oTrue,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.PageSetup.FirstPageTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterMiddleBin;
doc.PrintOut(ref oFalse, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oFalse,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
oWord.ActivePrinter = activePrinter;
oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
}
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:30,代码来源:Report.cs
示例3: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
fileName = FileUpload1.PostedFile.FileName;
myfullPath = Server.MapPath("Files/" + fileName);
FileUpload1.SaveAs(Server.MapPath("Files/" + fileName));
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object miss = System.Reflection.Missing.Value;
object path = Server.MapPath("Files/" + fileName);
object readOnly = true;
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
string totaltext = "";
for (int i = 0; i < docs.Paragraphs.Count; i++)
{
totaltext += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
}
PreviewTheoryTextBox.Text = totaltext;
//kratao to onoma tou arxeiou doc se label pou den fainetai
LabelToKeepFileName.Text = fileName;
docs.Close();
word.Quit();
FileUpload1.Visible = false;
}
开发者ID:ksksAsa,项目名称:aepTrain1,代码行数:25,代码来源:InsertTheory.aspx.cs
示例4: SaveDocAsXPS
public static void SaveDocAsXPS(string fileName)
{
Microsoft.Office.Interop.Word.Application oWord;
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
string currentPrinter = oWord.ActivePrinter;
oWord.ActivePrinter = "Microsoft XPS Document Writer";
Object docFileName = fileName;
Object xpsFileName = fileName.Replace(".doc", ".xps");
Object fileFormat = "wdFormatDocument";
if (System.IO.File.Exists(docFileName.ToString()) == true)
{
Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Open(ref docFileName, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object oOutputFile = xpsFileName;
doc.PrintOut(ref oFalse, ref oFalse, ref oMissing, ref oOutputFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
oWord.ActivePrinter = currentPrinter;
oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
}
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:32,代码来源:FileConversionHelper.cs
示例5: Main
static void Main(string[] args)
{
//using Word = Microsoft.Office.Interop.Word;
object fileName = Path.Combine(@"D:\VS2010Workspace\WordDocReplaceTest\WordDocReplaceTest\bin\Release", "TestDoc.docx");
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = false };
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);
aDoc.Activate();
Microsoft.Office.Interop.Word.Find fnd = wordApp.ActiveWindow.Selection.Find;
fnd.ClearFormatting();
fnd.Replacement.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
fnd.Text = "{替换前内容}";
fnd.Replacement.Text = "替换后内容-updated";
fnd.Execute(Replace: Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll);
aDoc.Save();
aDoc.Close(ref missing, ref missing, ref missing);
wordApp.Quit(ref missing, ref missing, ref missing);
}
开发者ID:Alexenix,项目名称:UtilityTools,代码行数:28,代码来源:Program.cs
示例6: RevisarOrtografia
private static string RevisarOrtografia(string texto)
{
var app = new Microsoft.Office.Interop.Word.Application();
string corregido = string.Empty;
if (!String.IsNullOrEmpty(texto))
{
app.Visible = false;
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = false;
Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate,
ref documentType, ref visible);
doc1.Words.First.InsertBefore(texto);
object optional = Missing.Value;
doc1.CheckSpelling(
ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);
object first = 0;
object last = doc1.Characters.Count - 1;
corregido = doc1.Range(ref first, ref last).Text;
}
object saveChanges = false;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
app.Application.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
return corregido;
}
开发者ID:joelgasso,项目名称:blogcodes,代码行数:30,代码来源:Form1.cs
示例7: CreateAWord
public void CreateAWord()
{
//实例化word应用对象
this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
Object myNothing = System.Reflection.Missing.Value;
this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);
}
开发者ID:shady32,项目名称:WordMaker,代码行数:8,代码来源:WordMacker.cs
示例8: SpellCheck
public SpellCheck()
{
this.m_WordApp = new Microsoft.Office.Interop.Word.Application();
this.m_WordApp.Visible = false;
this.m_WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oTrue);
InitializeComponent();
}
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:8,代码来源:SpellCheck.xaml.cs
示例9: WordApplication
private WordApplication()
{
this.m_WordApp = new Microsoft.Office.Interop.Word.Application();
this.m_WordApp.Visible = false;
this.m_Documents = this.m_WordApp.Documents;
this.m_Document = this.m_Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oTrue);
this.m_WordSuggestionList = new List<string>();
}
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:8,代码来源:WordApplication.cs
示例10: OpenFile
void OpenFile(string filepath, int selectionstart)
{
cache["lastdir"] = Path.GetDirectoryName(filepath);
string fileext = Path.GetExtension(filepath).ToLower();
if (fileext == ".doc" || fileext == ".docx")
{
object oMissing = System.Reflection.Missing.Value;
object isReadOnly = true;
Microsoft.Office.Interop.Word._Application oWord;
Microsoft.Office.Interop.Word._Document oDoc;
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
object fileName = filepath;
oDoc = oWord.Documents.Open(ref fileName,
ref oMissing, ref isReadOnly, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
this.rtbxMain.Text = oDoc.Content.Text;
oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
if (MessageBox.Show("转换为RTF文档并重新打开?", "转换格式", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
string newrtfpath = filepath + ".rtf";
this.rtbxMain.SaveFile(newrtfpath, RichTextBoxStreamType.RichText);
MessageBox.Show("转换为rtf成功.\r\n保存位置:" + newrtfpath, "转换格式");
OpenFile(newrtfpath, selectionstart);
return;
}
}
else
{
FileStream fs = File.Open(filepath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs, Encoding.Default, true);
if (fileext == ".rtf")
{
this.rtbxMain.Rtf = sr.ReadToEnd();
this.rtbxMain.Font = new Font("微软雅黑", 14f);
}
else
{
rtbxMain.Text = sr.ReadToEnd();
}
sr.Close();
fs.Close();
fs.Dispose();
sr.Dispose();
}
rtbxMain.SelectionStart = selectionstart;
currentfilepath = filepath;
this.Text = Path.GetFileNameWithoutExtension(currentfilepath);
this.Icon = ((System.Drawing.Icon)(new System.ComponentModel.ComponentResourceManager(typeof(MainForm)).GetObject("$this.Icon")));
tsmiReplaceWindowsTitle.Text = "隐藏标题";
this.tsmiCurrentFilename.Text = this.Text;
this.notifyIcon1.Text = this.Text;
}
开发者ID:Natsuwind,项目名称:DeepInSummer,代码行数:58,代码来源:MainForm.cs
示例11: OpenDocument
public static DocumentWrapper OpenDocument(String path)
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
DocumentWrapper wrapper = new DocumentWrapper();
wrapper.Application = app;
wrapper.Document = app.Documents.Open(path);
return wrapper;
}
开发者ID:tojoirinah,项目名称:Refonte-Recueil-One,代码行数:10,代码来源:MSWordInteropHelper.cs
示例12: Initialize
protected override void Initialize() {
base.Initialize();
this.Application = this.GetHostItem<Microsoft.Office.Interop.Word.Application>(typeof(Microsoft.Office.Interop.Word.Application), "Application");
Globals.ThisAddIn = this;
global::System.Windows.Forms.Application.EnableVisualStyles();
this.InitializeCachedData();
this.InitializeControls();
this.InitializeComponents();
this.InitializeData();
}
开发者ID:bovender,项目名称:VstoAddinInstaller,代码行数:10,代码来源:ThisAddIn.Designer.cs
示例13: Dispose
public void Dispose()
{
this._wordApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(this._wordApplication);
System.Runtime.InteropServices.Marshal.ReleaseComObject(this._wordDocument);
this._wordApplication = null;
this._wordDocument = null;
GC.Collect();
GC.Collect();
}
开发者ID:shady32,项目名称:WordMaker,代码行数:10,代码来源:WordMacker.cs
示例14: DoInteropDemo
public static String DoInteropDemo(String filePath)
{
var wordApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc =
wordApp.Documents.Open(filePath, ReadOnly: true);
dynamic docProperties = doc.BuiltInDocumentProperties;
string authorName = docProperties["Author"].Value;
doc.Close(SaveChanges: false);
return authorName;
}
开发者ID:alainlompo,项目名称:csharp-warmup-samples,代码行数:10,代码来源:SimpleWordInterop.cs
示例15: OnConnection
/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2 interface.
/// Receives notification that the Add-in is being loaded.
/// </summary>
/// <param name="application">Root object of the host application.</param>
/// <param name="connectMode"> Describes how the Add-in is being loaded.</param>
/// <param name="addInInst">Object representing this Add-in.</param>
/// <param name="custom"></param>
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_application = (Application) application;
_presenter = new ApplicationPresenter(_application);
_addInInstance = addInInst;
if (connectMode != ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}
开发者ID:Dmdv,项目名称:InwordRemover,代码行数:19,代码来源:Connect.cs
示例16: QuitApplication
/// <summary>
/// Закрытие приложения
/// </summary>
public void QuitApplication()
{
if (application != null)
{
range = null;
table = null;
document = null;
application.Quit();
application = null;
}
}
开发者ID:PAlAl,项目名称:ImportMStoDB,代码行数:15,代码来源:ThematicPlanProcessor.cs
示例17: btn_Read_Click
private void btn_Read_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;//获取缺少的object类型值
string[] P_str_Names = txt_Excel.Text.Split(',');//存储所有选择的Excel文件名
object P_obj_Name;//存储遍历到的Excel文件名
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();//实例化Word对象
if (txt_Word.Text.EndsWith("\\"))//判断路径是否以\结尾
P_obj_WordName = txt_Word.Text + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc";//记录Word文件路径及名称
else
P_obj_WordName = txt_Word.Text + "\\" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc";//记录Word文件路径及名称
Microsoft.Office.Interop.Word.Table table;//声明Word表格对象
Microsoft.Office.Interop.Word.Document document = new Microsoft.Office.Interop.Word.Document();//声明Word文档对象
document = word.Documents.Add(ref missing, ref missing, ref missing, ref missing);//新建Word文档
Microsoft.Office.Interop.Word.Range range ;//声明范围对象
int P_int_Rows = 0, P_int_Columns = 0;//存储工作表中数据的行数和列数
object P_obj_start = 0, P_obj_end = 0;//分别记录创建表格的开始和结束范围
object P_obj_Range = Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd;//定义要合并的范围位置
for (int i = 0; i < P_str_Names.Length - 1; i++)//遍历所有选择的Excel文件名
{
P_obj_Name = P_str_Names[i];//记录遍历到的Excel文件名
List<string> P_list_SheetName = CBoxBind(P_obj_Name.ToString());//获取指定Excel中的所有工作表
for (int j = 0; j < P_list_SheetName.Count; j++)//遍历所有工作表
{
range = document.Range(ref missing, ref missing);//获取Word范围
range.InsertAfter(P_obj_Name + "——" + P_list_SheetName[j] + "工作表");//插入文本
range.Font.Name = "宋体";//设置字体
range.Font.Size = 10;//设置字体大小
DataSet myds = CBoxShowCount(P_obj_Name.ToString(), P_list_SheetName[j]);//获取工作表中的所有数据
P_int_Rows = myds.Tables[0].Rows.Count;//记录工作表的行数
P_int_Columns = myds.Tables[0].Columns.Count;//记录工作表的列数
range.Collapse(ref P_obj_Range);//合并范围
if (P_int_Rows > 0 && P_int_Columns > 0)//判断如果工作表中有记录
{
//在指定范围处添加一个指定行数和列数的表格
table = range.Tables.Add(range, P_int_Rows, P_int_Columns, ref missing, ref missing);
for (int r = 0; r < P_int_Rows; r++)//遍历行
{
for (int c = 0; c < P_int_Columns; c++)//遍历列
{
table.Cell(r + 1, c + 1).Range.InsertAfter(myds.Tables[0].Rows[r][c].ToString());//将遍历到的数据添加到Word表格中
}
}
}
object P_obj_Format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;//定义Word文档的保存格式
word.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;//设置保存时不显示对话框
//保存Word文档
document.SaveAs(ref P_obj_WordName, ref P_obj_Format, 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);
}
}
document.Close(ref missing, ref missing, ref missing);//关闭Word文档
word.Quit(ref missing, ref missing, ref missing);//退出Word应用程序
MessageBox.Show("已经成功将多个Excel文件的内容读取到了一个Word文档中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
开发者ID:TGHGH,项目名称:C-1200,代码行数:53,代码来源:Frm_Main.cs
示例18: ReporterMSWord
public ReporterMSWord(ReportData inputData
, string templatePath, string outputFilePath, Margins margins)
{
// absolute output file path
string absOutputFilePath = string.Empty;
if (Path.IsPathRooted(outputFilePath))
absOutputFilePath = outputFilePath;
else
absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
// absolute template path
string absTemplatePath = string.Empty;
if (Path.IsPathRooted(templatePath))
absTemplatePath = templatePath;
else
absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));
// does output directory exists
string outDir = Path.GetDirectoryName(absOutputFilePath);
if (!Directory.Exists(outDir))
{
try { Directory.CreateDirectory(outDir); }
catch (System.UnauthorizedAccessException /*ex*/)
{ throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
catch (Exception ex)
{ throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
}
// html file path
string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");
BuildAnalysisReport(inputData, absTemplatePath, htmlFilePath);
// opens word
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(htmlFilePath, false, true, NoEncodingDialog: true);
// embed pictures (unlinking images)
for (int i = 1; i <= wordDoc.InlineShapes.Count; ++i)
{
if (null != wordDoc.InlineShapes[i].LinkFormat && !wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument)
wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument = true;
}
// set margins (unit?)
wordDoc.PageSetup.TopMargin = wordApp.CentimetersToPoints(margins.Top);
wordDoc.PageSetup.BottomMargin = wordApp.CentimetersToPoints(margins.Bottom);
wordDoc.PageSetup.RightMargin = wordApp.CentimetersToPoints(margins.Right);
wordDoc.PageSetup.LeftMargin = wordApp.CentimetersToPoints(margins.Left);
// set print view
wordApp.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
wordDoc.SaveAs(absOutputFilePath, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault);
_log.Info(string.Format("Saved doc report to {0}", outputFilePath));
// delete image directory
DeleteImageDirectory();
// delete html report
File.Delete(htmlFilePath);
}
开发者ID:TimVelo,项目名称:StackBuilder,代码行数:53,代码来源:ReporterMSWord.cs
示例19: btn_Read_Click
private void btn_Read_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();//实例化Word对象
Microsoft.Office.Interop.Word.Table table;//声明Word表格对象
int P_int_TableCount = 0, P_int_Row = 0, P_int_Column = 0;//定义3个变量,分别用来存储表格数量、表格中的行数、列数
string P_str_Content;//存储Word表格的单元格内容
object missing = System.Reflection.Missing.Value;//获取缺少的object类型值
string[] P_str_Names = txt_Word.Text.Split(',');//存储所有选择的Word文件名
object P_obj_Name;//存储遍历到的Word文件名
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象
//打开指定的Excel文件
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Application.Workbooks.Open(txt_Excel.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Microsoft.Office.Interop.Excel.Worksheet newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add(missing, missing, missing, missing);//创建新工作表
for (int i = 0; i < P_str_Names.Length - 1; i++)//遍历所有选择Word文件名
{
P_obj_Name = P_str_Names[i];//记录遍历到的Word文件名
//打开Word文档
Microsoft.Office.Interop.Word.Document document = word.Documents.Open(ref P_obj_Name, 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);
P_int_TableCount = document.Tables.Count;//获取Word文档中表格的数量
if (P_int_TableCount > 0)//判断表格数量是否大于0
{
for (int j = 1; j <= P_int_TableCount; j++)//遍历所有表格
{
table = document.Tables[j];//记录遍历到的表格
P_int_Row = table.Rows.Count;//获取表格行数
P_int_Column = table.Columns.Count;//获取表格列数
for (int row = 1; row <= P_int_Row; row++)//遍历表格中的行
{
for (int column = 1; column <= P_int_Column; column++)//遍历表格中的列
{
P_str_Content = table.Cell(row, column).Range.Text;//获取遍历到的单元格内容
newWorksheet.Cells[i + row, column] = P_str_Content.Substring(0, P_str_Content.Length - 2);//将遍历到的单元格内容添加到Excel单元格中
}
}
}
}
else
{
if (P_int_Row == 0)//判断前面是否已经填充过表格
newWorksheet.Cells[i + P_int_Row + 1, 1] = document.Content.Text;//直接将Word文档内容添加到工作表中
else
newWorksheet.Cells[i + P_int_Row, 1] = document.Content.Text;//直接将Word文档内容添加到工作表中
}
document.Close(ref missing, ref missing, ref missing);//关闭Word文档
}
excel.Application.DisplayAlerts = false;//不显示提示对话框
workbook.Save();//保存工作表
workbook.Close(false, missing, missing);//关闭工作表
word.Quit(ref missing, ref missing, ref missing);//退出Word应用程序
MessageBox.Show("已经成功将多个Word文档的内容合并到了Excel的同一个数据表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
开发者ID:TGHGH,项目名称:C-1200,代码行数:51,代码来源:Frm_Main.cs
示例20: Initialize
public void Initialize() {
this.HostItemHost = ((Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)(this.RuntimeCallback.GetService(typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider))));
this.DataHost = ((Microsoft.VisualStudio.Tools.Applications.Runtime.ICachedDataProvider)(this.RuntimeCallback.GetService(typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.ICachedDataProvider))));
object hostObject = null;
this.HostItemHost.GetHostObject("Microsoft.Office.Interop.Word.Application", "Application", out hostObject);
this.Application = ((Microsoft.Office.Interop.Word.Application)(hostObject));
Globals.ThisAddIn = this;
System.Windows.Forms.Application.EnableVisualStyles();
this.InitializeCachedData();
this.InitializeControls();
this.InitializeComponents();
this.InitializeData();
this.BeginInitialization();
}
开发者ID:head-thrash,项目名称:VSTO-CAB,代码行数:14,代码来源:ThisAddIn.Designer.cs
注:本文中的Microsoft.Office.Interop.Word.Application类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论