最近做项目用到了layui 里面的 table ,点击某一行选中当前行的radio,解决办法如下:
07
2020
10
12
2020
07
Spire.doc对word的操作总结
Word操作汇总 1、 打开已有word文件,这是要处理word文件的最基本也是必须的步骤。他提供了三种方法。 方法1:从已知特定的文档中初始化一个新的Document 类的实例 Document document = new Document(@"..\..\Sample.docx"); 方法2、从文件中加载一个word文件 Document document = new Document(); document.LoadFromFile(@"..\..\Sample.docx"); 方法3、从流文件中加载word文件 Stream stream = File.OpenRead(@"..\..\Sample.docx"); Document document = new Document(stream); 2、如何创建表格 Document document = new Document(); Section section = document.AddSection(); Table table = section.AddTable(true); table.ResetCells(2, 3); TableRow row = table.Rows[0]; row.IsHeader = true; Paragraph para = row.Cells[0].AddParagraph(); TextRange TR = para.AppendText("Item"); para = row.Cells[1].AddParagraph(); TR = para.AppendText("Description"); para = row.Cells[2].AddParagraph(); TR = para.AppendText("Qty"); document.SaveToFile("WordTable.docx"); System.Diagnostics.Process.Start("WordTable.docx"); 我们还可以设置行高和列宽 3、如何插入超链接?你可以插入两种超链接,Email 链接和webmail 链接。 Documentdocument =newDocument(); Section section = document.AddSection(); //Insert URL hyperlink Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Home page"); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph = section.AddParagraph(); paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com",HyperlinkType.WebLink); //Insert email address hyperlink paragraph = section.AddParagraph(); paragraph.AppendText("Contact US"); paragraph.ApplyStyle(BuiltinStyle.Heading2); paragraph = section.AddParagraph(); paragraph.AppendHyperlink("mailto:support@e-iceblue.com", "support@e-iceblue.com",HyperlinkType.EMailLink); document.SaveToFile("Hyperlink.docx"); System.Diagnostics.Process.Start("Hyperlink.docx"); 4、如何加入注解 Document document = new Document(); Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Home Page of "); TextRange textRange = paragraph.AppendText("e-iceblue"); Comment comment1 = paragraph.AppendComment("www.e-iceblue.com"); comment1.AddItem(textRange); comment1.Format.Author = "Harry Hu"; comment1.Format.Initial = "HH"; document.SaveToFile("Comment.docx"); System.Diagnostics.Process.Start("Comment.docx"); 5、如何加入书签 Document document = new Document(); Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); paragraph.AppendBookmarkStart("SimpleBookMark"); paragraph.AppendText("This is a simple book mark."); paragraph.AppendBookmarkEnd("SimpleBookMark"); document.SaveToFile("Bookmark.docx"); System.Diagnostics.Process.Start("Bookmark.docx"); 6、合并邮件 Document document = new Document(); document.LoadFromFile("Fax.doc"); string[] filedNames = new string[] { "Contact Name", "Fax", "Date" }; string[] filedValues = new string[] { "John Smith", "+1 (69) 123456", System.DateTime.Now.Date.ToString() }; document.MailMerge.Execute(filedNames, filedValues); document.SaveToFile("MailMerge.doc", FileFormat.Doc); System.Diagnostics.Process.Start("MailMerge.doc"); 7、加入表单,这部分包含创建以及填入表单域。 创建表单 //Add new section to document Section section = document.AddSection(); //Add Form to section private void AddForm(Section section) //add text input field TextFormField field = fieldParagraph.AppendField(fieldId, FieldType.FieldFormTextInput) as TextFormField; //add dropdown field DropDownFormField list = fieldParagraph.AppendField(fieldId, FieldType.FieldFormDropDown) as DropDownFormField; //add checkbox field fieldParagraph.AppendField(fieldId, FieldType.FieldFormCheckBox); 填入表单域 //Fill data from XML file using (Stream stream = File.OpenRead(@"..\..\..\Data\User.xml")) { XPathDocument xpathDoc = new XPathDocument(stream); XPathNavigator user = xpathDoc.CreateNavigator().SelectSingleNode("/user"); Fill data: foreach (FormField field in document.Sections[0].Body.FormFields) { String path = String.Format("{0}/text()", field.Name); XPathNavigator propertyNode = user.SelectSingleNode(path); if (propertyNode != null) { switch (field.Type) { case FieldType.FieldFormTextInput: field.Text = propertyNode.Value; break; case FieldType.FieldFormDropDown: DropDownFormField combox = field as DropDownFormField; for(int i = 0; i < combox.DropDownItems.Count; i++) { if (combox.DropDownItems[i].Text == propertyNode.Value) { combox.DropDownSelectedIndex = i; break; } if (field.Name == "country" && combox.DropDownItems[i].Text =="Others") { combox.DropDownSelectedIndex = i; } } break; case FieldType.FieldFormCheckBox: if (Convert.ToBoolean(propertyNode.Value)) { CheckBoxFormField checkBox = field as CheckBoxFormField; checkBox.Checked = true; } break; } } } } 8、合并word文档 //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); 9、保护文档。你可以设置密码或者加入水印来进行保护。文字和图片的水印都支持。 //Protect with password document.Encrypt("eiceblue"); //Add Text watermark: TextWatermark txtWatermark = new TextWatermark(); txtWatermark.Text = "Microsoft"; txtWatermark.FontSize = 90; txtWatermark.Layout = WatermarkLayout.Diagonal; document.Watermark = txtWatermark; //Add Image watermark: PictureWatermark picture = new PictureWatermark(); picture.Picture = System.Drawing.Image.FromFile(@"..\imagess.jpeg"); picture.Scaling = 250; document.Watermark = picture; 10、转换功能是在处理word文档时最常见的操作了。使用免费版的Spire.doc for .NET, 转换变得很简单。只要包含三行类似的代码你就可以把word转换成其他常用格式,像PDF,HTML和图片。 Word转换成PDF SaveToFile("Target PDF.PDF", FileFormat.PDF); Word转换成图片 Image image = document.SaveToImages(0, ImageType.Bitmap); image.Save("Sample.tiff", ImageFormat.Tiff); Word转换成HTML document.SaveToFile("Target HTML.html", FileFormat.Html); WordDocViewer(""Target HTML.html"); 结论: 这是一个免费又强大的C# word 组件,它不需要 Word automatio即可运行,并且任何第三方的功能都囊括。
发布:网站编辑 | 分类:c#操作word系列 | 评论:0 | 浏览:
12
2020
07
sprie pdf 导出前几页
C# 将一个 PDF 页面拆分为多页
//加载PDF文档 PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("New Zealand.pdf"); //获取第一页 PdfPageBase page = pdf.Pages[0]; //创建新PDF文档 PdfDocument newPdf = new PdfDocument(); //移除新文档的页边距 newPdf.PageSettings.Margins.All = 0; //设置新文档页面的宽度等于原文档第一页的宽度,页面高度等于原文档第一页高度的一半 newPdf.PageSettings.Width = page.Size.Width; newPdf.PageSettings.Height = page.Size.Height / 2; //添加新页面到新文档 PdfPageBase newPage = newPdf.Pages.Add(); PdfTextLayout format = new PdfTextLayout(); format.Break = PdfLayoutBreakType.FitPage; format.Layout = PdfLayoutType.Paginate; //根据原文档第一页创建模板,并将模板画到新文档的新添加页面,页面画满之后自动分页 page.CreateTemplate().Draw(newPage, new PointF(0, 0), format); //保存 newPdf.SaveToFile("HorizontallySplit.pdf"); newPdf.Close(); pdf.Close();
纵向拆分
发布:网站编辑 | 分类:c#操作word系列 | 评论:0 | 浏览:
12
2020
07
Word按页读取内容
/// <summary> /// Word按页读取内容 /// </summary> /// <param name="page">页数</param> /// <param name="isHtml">html或纯文本</param> /// <returns></returns> /// public string ReadPage(int page, bool isHtml) { object objWhat = Word.WdGoToItem.wdGoToPage; object objWhich = Word.WdGoToDirection.wdGoToAbsolute; object objPage = page; Word.Range range1 = oDoc.GoTo(ref objWhat, ref objWhich, ref objPage, ref missing); Word.Range range2 = range1.GoToNext(Word.WdGoToItem.wdGoToPage); object objStart = range1.Start; object objEnd = range2.Start ; if (range1.Start == range2.Start) objEnd = oDoc.Characters.Count;//最后一页 oDoc.Range(ref objStart, ref objEnd).Copy(); if (isHtml) { MemoryStream stream = Clipboard.GetData("Html Format") as MemoryStream; stream.Position = 0;//解决从剪切板复制中文内容乱码的问题www.xuehi.com byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); return Encoding.UTF8.GetString(bytes); } else { byte[] bytes = Encoding.Default.GetBytes((string)Clipboard.GetData(DataFormats.Text)); return Encoding.GetEncoding("gb2312").GetString(bytes); } }
发布:网站编辑 | 分类:c#操作word系列 | 评论:0 | 浏览:
12
2020
07
C#获取Word文档操作
using MSWord = Microsoft.Office.Interop.Word; MSWord.Application wordApp; //Word应用程序变量 MSWord.Document wordDoc; //Word文档变量 Object Nothing = Missing.Value; //初始化 wordApp = new MSWord.ApplicationClass(); wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, refNothing, ref Nothing); // 新建Word // 打开已存在的Word object FileName = strPath; object readOnly = false; object isVisible = true; wordDoc = wordApp.Documents.Open(ref FileName, ref Nothing, refreadOnly, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, refNothing, ref Nothing, ref Nothing, ref isVisible, ref Nothing, ref Nothing, refNothing, ref Nothing); // 计算Word文档页数 MSWord.WdStatistic stat = MSWord.WdStatistic.wdStatisticPages; int num = wordDoc.ComputeStatistics(stat, ref Nothing); // 跳转到指定书签 object what = MSWord.WdGoToItem.wdGoToBookmark; object BookMarkName = "BookMark1"; wordDoc.ActiveWindow.Selection.GoTo(ref what, ref Nothing, refNothing, ref BookMarkName); MessageBox.Show(wordDoc.ActiveWindow.Selection.Paragraphs[1].Range.Text.ToString()); //跳转到指定页 object What = MSWord.WdGoToItem.wdGoToPage; object Which = MSWord.WdGoToDirection.wdGoToNext; object Name = "1"; // 页数 wordDoc.ActiveWindow.Selection.GoTo(ref What, ref Which, refNothing, ref Name); // 第二个参数可以用Nothing MessageBox.Show(wordDoc.ActiveWindow.Selection.Paragraphs[1].Range.Text.ToString()); MessageBox.Show(wordDoc.ActiveWindow.Selection.Sentences[1].Text.ToString()); MessageBox.Show(wordDoc.ActiveWindow.Selection.Paragraphs[1].Range.Sentences[1].Text.ToString()); MessageBox.Show(wordDoc.Content.Paragraphs[8].Range.Text.ToString()); MessageBox.Show(wordDoc.Content.Paragraphs[8].Range.Sentences[1].Text.ToString()); //插入段落并分页 Word.Paragraph oPara4; oPara4 = mydoc.Content.Paragraphs.Add(ref oMissing); oPara4.Range.Text = "附图一:"; oPara4.Range.Font.Name = "宋体"; oPara4.Range.Font.Size = 10.5f; oPara4.Range.InsertParagraphAfter(); insertChart(saveDocPath);//插入excel-chart oPara4.Range.InsertParagraphAfter(); //插入分页符 insertBreakNextPage(); //用正则表达式分割段落 string string2 = " 段落1。\r\n 段落2。\r\n 段落3。"; string[] Paras = System.Text.RegularExpressions.Regex.Split(string2, @"\r\n"); //插入回车符 word.Selection.TypeParagraph(); //插入回格符 word.Selection.TypeBackspace(); //跳转到文档结尾 object wd_story = Word.WdUnits.wdStory; word.Selection.EndKey(ref wd_story, ref oMissing);
发布:网站编辑 | 分类:c#操作word系列 | 评论:0 | 浏览:
04
2020
07
vsto 开发office 集合
vsto下开发wps插件
https://www.cnblogs.com/wangqiang3311/p/8134072.html
WPS插件开发流程(1)
https://blog.csdn.net/wenjian005/article/details/80161633
WPS插件开发流程(2)
https://blog.csdn.net/wenjian005/article/details/80248185
c#开发wps插件
https://www.cnblogs.com/wangqiang3311/p/7205416.html
c#开发wps插件(2)
https://www.cnblogs.com/wangqiang3311/p/7206105.html
wpsAddin示例代码
https://github.com/wangqiang3311/wpsAddin
c#开发wps插件(3)部署
https://www.cnblogs.com/wangqiang3311/p/7206406.html
发布:网站编辑 | 分类:c#操作word系列 | 评论:0 | 浏览:
03
2020
07
C#修改文件或文件夹名称
move()方法其实就是重命名的。 另外,使用DirectoryInfo中的moveto也是可以实现的。 string srcFileName = @"D:/a.txt"; string destFileName = @"D:/b.txt"; string srcFolderPath = @"D:/1"; string destFolderPath = @"D:/6"; //方法一 if (System.IO.File.Exists(srcFileName)) { System.IO.File.Move(srcFileName, destFileName); } if (System.IO.Directory.Exists(srcFolderPath)) { System.IO.Directory.Move(srcFolderPath, destFolderPath); } //方法二 if (System.IO.File.Exists(srcFileName)) { System.IO.FileInfo file = new System.IO.FileInfo(srcFileName); file.MoveTo(destFileName); } if (System.IO.Directory.Exists(srcFolderPath)) { System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(srcFolderPath); folder.MoveTo(destFolderPath); }
发布:网站编辑 | 分类:WPF | 评论:0 | 浏览:
03
2020
07
c# 路径截取
string filePath = @"E:\Randy0528\中文目录\JustTest.rar"; Response.Write("文件路径:"+filePath); Response.Write("<br/>更改路径字符串的扩展名。<br/>"); Response.Write(System.IO.Path.ChangeExtension(filePath, "txt")); Response.Write("<br/>返回指定路径字符串的目录信息。。<br/>"); Response.Write(System.IO.Path.GetDirectoryName(filePath)); Response.Write("<br/>返回指定的路径字符串的扩展名。<br/>"); Response.Write(System.IO.Path.GetExtension(filePath)); Response.Write("<br/>返回指定路径字符串的文件名和扩展名。<br/>"); Response.Write(System.IO.Path.GetFileName(filePath)); Response.Write("<br/>返回不具有扩展名的指定路径字符串的文件名。<br/>"); Response.Write(System.IO.Path.GetFileNameWithoutExtension(filePath)); Response.Write("<br/>获取指定路径的根目录信息。<br/>"); Response.Write(System.IO.Path.GetPathRoot(filePath)); Response.Write("<br/>返回随机文件夹名或文件名。<br/>"); Response.Write(System.IO.Path.GetRandomFileName()); Response.Write("<br/>创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。<br/>"); Response.Write(System.IO.Path.GetTempFileName()); Response.Write("<br/>返回当前系统的临时文件夹的路径。<br/>"); Response.Write(System.IO.Path.GetTempPath()); Response.Write("<br/>确定路径是否包括文件扩展名。<br/>"); Response.Write(System.IO.Path.HasExtension(filePath)); Response.Write("<br/>获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。<br/>"); Response.Write(System.IO.Path.IsPathRooted(filePath));
执行结果
文件路径:E:\Randy0528\中文目录\JustTest.rar 更改路径字符串的扩展名。 E:\Randy0528\中文目录\JustTest.txt 返回指定路径字符串的目录信息。。 E:\Randy0528\中文目录 返回指定的路径字符串的扩展名。 .rar 返回指定路径字符串的文件名和扩展名。 JustTest.rar 返回不具有扩展名的指定路径字符串的文件名。 JustTest 获取指定路径的根目录信息。 E:\ 返回随机文件夹名或文件名。 ct2h5b2h.sed 创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。 C:\Documents and Settings\Randy\Local Settings\Temp\tmpAD.tmp 返回当前系统的临时文件夹的路径。 C:\Documents and Settings\Randy\Local Settings\Temp\ 确定路径是否包括文件扩展名。 True
获取一个值,该值指示指定的路径字符串是包含绝对路径信息还是包含相对路径信息。
string fullPath = @"\WebSite1\Default.aspx"; string filename = System.IO.Path.GetFileName(fullPath);//文件名 “Default.aspx” string extension = System.IO.Path.GetExtension(fullPath);//扩展名 “.aspx” string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullPath);// 没有扩展名的文件名 “Default”
发布:网站编辑 | 分类:WPF | 评论:0 | 浏览:
02
2020
07
预定义的类型“Microsoft.CSharp.RuntimeBinder.Binder”未定义或未导入
出现这个错误:
预定义的类型“Microsoft.CSharp.RuntimeBinder.Binder”未定义或未导入
发布:网站编辑 | 分类:WPF | 评论:0 | 浏览:
02
2020
07
wps 转 pdf C# 实现
项目需求:不打算用office自带的组件实现word转pdf操作
环境需求:安装wps2016专业版
发布:网站编辑 | 分类:c#操作word系列 | 评论:0 | 浏览: