ImageVerifierCode 换一换
格式:DOC , 页数:15 ,大小:326KB ,
资源ID:3539886      下载积分:20 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-3539886.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C#编写的Word操作类,有换页,添加表格,文竟δdoc.doc)为本站会员(hw****26)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

C#编写的Word操作类,有换页,添加表格,文竟δdoc.doc

1、using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Drawing;using Word = Microsoft.Office.Interop.Word;using Microsoft.Office.Interop.Word;using System.Windows.Forms;/* * 文件 名 : * * 声明 : * * 创建者 : 黄聪* * 创建日期 : 2009.10.8* * 修改者 : 黄聪* * 最新修改

2、日期 : 2009.10.8*/namespace Tool/* * 类名 : WordPlayer* * 声明 : * * 创建者 : 黄聪* * 创建日期 : 2009.7.15* * 修改者 : 黄聪* * 最新修改日期 : 2009.7.15*/public class WordPlayer#region - 属性 -private static Microsoft.Office.Interop.Word._Application oWord = null;private static Microsoft.Office.Interop.Word._Document odoc = nul

3、l;private static Microsoft.Office.Interop.Word._Document oDocgetif (odoc = null)odoc = oWord.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);return odoc;setif (value != null)odoc = value;private static object Nothing = System.Reflection.Missing.Value;public enum Orientation横板,竖板pub

4、lic enum Alignment左对齐,居中,右对齐#endregion#region - 添加文档 -#region - 创建并打开一个空的 word 文档进行 编辑 -public static void OpenNewWordFileToEdit()oDoc = oWord.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);#endregion#endregion#region - 创建新 Word -public static bool CreateWord(bool isVisible)tryoWo

5、rd = new Microsoft.Office.Interop.Word.Application();oWord.Visible = isVisible;return true;catch (Exception)return false;public static bool CreateWord()return CreateWord(false);#endregion#region - 打开文档 -public static bool Open(string filePath, bool isVisible)tryoWord.Visible = isVisible;object path

6、= filePath;oDoc = oWord.Documents.Open(ref path,ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);return true;catch (Exception)return false;#endregion#region

7、 - 插入表格 -public static bool InsertTable(DataTable dt, bool haveBorder, double colWidths)tryobject Nothing = System.Reflection.Missing.Value;int lenght = oDoc.Characters.Count - 1;object start = lenght;object end = lenght;/表格起始坐标Microsoft.Office.Interop.Word.Range tableLocation = oDoc.Range(ref start

8、, ref end);/添加 Word 表格 Microsoft.Office.Interop.Word.Table table = oDoc.Tables.Add(tableLocation, dt.Rows.Count, dt.Columns.Count, ref Nothing, ref Nothing);if (colWidths != null)for (int i = 0; i colWidths.Length; i+)table.Columnsi + 1.Width = (float)(28.5F * colWidthsi);/设置 TABLE 的样式table.Rows.Hei

9、ghtRule = Microsoft.Office.Interop.Word.WdRowHeightRule.wdRowHeightAtLeast;table.Rows.Height = oWord.CentimetersToPoints(float.Parse(“0.8“);table.Range.Font.Size = 10.5F;table.Range.Font.Name = “宋体“;table.Range.Font.Bold = 0;table.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdPar

10、agraphAlignment.wdAlignParagraphCenter;table.Range.Cells.VerticalAlignment = Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;if (haveBorder = true)/设置外框样式table.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;table.Borders.InsideL

11、ineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;/样式设置结束for (int row = 0; row dt.Rows.Count; row+)for (int col = 0; col dt.Columns.Count; col+)table.Cell(row + 1, col + 1).Range.Text = dt.Rowsrowcol.ToString();return true;catch (Exception e)MessageBox.Show(e.ToString(), “错误提示“,

12、 MessageBoxButtons.OK, MessageBoxIcon.Error);return false;finallypublic static bool InsertTable(DataTable dt, bool haveBorder)return InsertTable(dt, haveBorder, null);public static bool InsertTable(DataTable dt)return InsertTable(dt, false, null);#endregion#region - 插入文本 -public static bool InsertTe

13、xt(string strText, System.Drawing.Font font, Alignment alignment, bool isAftre)tryWord.Range rng = oDoc.Content;int lenght = oDoc.Characters.Count - 1;object start = lenght;object end = lenght;rng = oDoc.Range(ref start, ref end);if (isAftre = true)strText += “rn“;rng.Text = strText;rng.Font.Name =

14、font.Name;rng.Font.Size = font.Size;if (font.Style = FontStyle.Bold) rng.Font.Bold = 1; /设置单元格中字体为粗体SetAlignment(rng, alignment);return true;catch (Exception)return false;public static bool InsertText(string strText)return InsertText(strText, new System.Drawing.Font(“宋体“, 10.5F, FontStyle.Bold), Ali

15、gnment.左对齐, false);#endregion#region - 设置对齐方式 -private static Microsoft.Office.Interop.Word.WdParagraphAlignment SetAlignment(Range rng, Alignment alignment)rng.ParagraphFormat.Alignment = SetAlignment(alignment);return SetAlignment(alignment);private static Microsoft.Office.Interop.Word.WdParagraph

16、Alignment SetAlignment(Alignment alignment)if (alignment = Alignment.居中)return Word.WdParagraphAlignment.wdAlignParagraphCenter;else if (alignment = Alignment.左对齐)return Word.WdParagraphAlignment.wdAlignParagraphLeft;else return Word.WdParagraphAlignment.wdAlignParagraphRight; #endregion#region - 页面

17、设置 -public static void SetPage(Orientation orientation, double width, double height, double topMargin, double leftMargin, double rightMargin, double bottomMargin)oDoc.PageSetup.PageWidth = oWord.CentimetersToPoints(float)width);oDoc.PageSetup.PageHeight = oWord.CentimetersToPoints(float)height);if (

18、orientation = Orientation.横板)oDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;oDoc.PageSetup.TopMargin = (float)(topMargin * 25);/上边距 oDoc.PageSetup.LeftMargin = (float)(leftMargin * 25);/左边距 oDoc.PageSetup.RightMargin = (float)(rightMargin * 25);/右边距 oDoc.P

19、ageSetup.BottomMargin = (float)(bottomMargin * 25);/下边距public static void SetPage(Orientation orientation, double topMargin, double leftMargin, double rightMargin, double bottomMargin)SetPage(orientation, 21, 29.7, topMargin, leftMargin, rightMargin, bottomMargin);public static void SetPage(double t

20、opMargin, double leftMargin, double rightMargin, double bottomMargin)SetPage(Orientation.竖板, 21, 29.7, topMargin, leftMargin, rightMargin, bottomMargin);#endregion#region - 插入分页符 -public static void InsertBreak()Word.Paragraph para;para = oDoc.Content.Paragraphs.Add(ref Nothing);object pBreak = (int

21、)WdBreakType.wdSectionBreakNextPage;para.Range.InsertBreak(ref pBreak);#endregion#region - 关闭当前文档 -public static bool CloseDocument()tryobject doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;oDoc.Close(ref doNotSaveChanges, ref Nothing, ref Nothing);oDoc = null;return true;catch (Exception)return false;#endregion#region - 关闭程序 -public static bool Quit()tryobject saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;oWord.Quit(ref saveOption, ref Nothing, ref Nothing);return true;catch (Exception)return false;#endregion#region - 保存文档 -

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。