public static void AddComment2() { WordDocument document = new WordDocument(); //Insert some content before bookmark Section section = document.Sections.AddSection(); Paragraph para = section.Blocks.AddParagraph(); para.Inlines.AddText("Sentence start "); //Create comment Comment comment = document.Comments.AddComment(); comment.Author = "iDiTect"; comment.Date = DateTime.Now; comment.Blocks.AddParagraph().Inlines.AddText("comment details"); //Insert comment to paragraph para.Inlines.Add(comment.CommentRangeStart); para.Inlines.AddText("text"); para.Inlines.Add(comment.CommentRangeEnd); //Insert some content after bookmark para.Inlines.AddText(" Sentence end."); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddComment2.docx")) { wordFile.Export(document, stream); } }
public static void AddImageWatermark() { WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx")); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Customize the setting of image watermark ImageWatermarkSettings setting = new ImageWatermarkSettings(); setting.Width = 100; setting.Height = 50; setting.Rotation = -45; using (Stream stream = File.OpenRead("watermark.png")) { setting.ImageSource = new Basic.Media.ImageSource(stream, "png"); } //Create watermark with settings Watermark imageWatermark = new Watermark(setting); //Add watermark to Header object builder.SetWatermark(imageWatermark, document.Sections[0].Headers.Add()); //builder.SetWatermark(imageWatermark, document.Sections[0], HeaderFooterType.Default); File.WriteAllBytes("AddImageWatermark.docx", wordFile.Export(document)); }
private void nextB_Click(object sender, EventArgs e) { if (canBeOpened(wdPathTB.Text) && canBeOpened(xlPathTB.Text)) { wdOriginalPath = wdPathTB.Text; wordFile = new WordFile(wdPathTB.Text); excelFile = new ExcelFile(xlPathTB.Text); wdCatalog = wordFile.getCatalog(); Info.marks = wordFile.getMarks(); Info.allFields = excelFile.getFields(); form2 = new Form2(); form2.ShowDialog(); for (int i = 2; i <= excelFile.getTotalRows(); i++) { //wordFile.closeFile(); proccessNewCopy(i); } MessageBox.Show(@"Успішно опрацьовано!"); } }
public static void AddTextWatermark() { WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx")); //Customize the setting of text watermark TextWatermarkSettings setting = new TextWatermarkSettings(); setting.Text = "watermark"; setting.Width = 100; setting.Height = 50; //The opacity value is between 0 and 1. setting.Opacity = 0.7; //Set the watermark rotation setting.Rotation = -45; setting.TextColor = Colors.Red; //Create watermark with settings Watermark textWatermark = new Watermark(setting); //Add watermark to Header object Header header = document.Sections[0].Headers.Add(); header.Watermarks.Add(textWatermark); File.WriteAllBytes("AddTextWatermark.docx", wordFile.Export(document)); }
public static void AddBookmark() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); builder.InsertLine("First paragraph in this document."); //Insert some content before bookmark builder.InsertText("Second paragraph start. "); //Select the content you want to bookmark TextInline textBookmark = builder.InsertText("This is bookmark. "); //Insert some content after bookmark builder.InsertText("Second paragraph end."); //Add bookmark with selected content builder.InsertBookmark("bookmark1", textBookmark, textBookmark); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddBookmark.docx")) { wordFile.Export(document, stream); } }
public static void AddBookmark2() { WordDocument document = new WordDocument(); //Insert some content before bookmark Section section = document.Sections.AddSection(); Paragraph para = section.Blocks.AddParagraph(); para.Inlines.AddText("Sentence start "); //Create bookmark Bookmark bookmark = new Bookmark(document, "bookmark2"); para.Inlines.Add(bookmark.BookmarkRangeStart); para.Inlines.AddText("text"); para.Inlines.Add(bookmark.BookmarkRangeEnd); //Insert some content after bookmark para.Inlines.AddText(" Sentence end."); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddBookmark2.docx")) { wordFile.Export(document, stream); } }
public InvoceService(HourseExcelParser hourseParser, FindColumnNumber findColumn, WordFile wordFile, GetAllSheets allsheets) { this._hourseParser = hourseParser; this._findColumn = findColumn; this._wordFile = wordFile; this._getAllSheets = allsheets; }
public HomeController(ILogger <HomeController> logger, InvoceService service, WordFile wordFile, GetAllSheets allsheets) { _logger = logger; this._service = service; this._wordFile = wordFile; this._getAllSheets = allsheets; }
public static void AddInlineImage() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Add in-line image using builder builder.InsertText("Simple sentence 1 in line. "); using (Stream stream = File.OpenRead("sample.jpg")) { builder.InsertImageInline(stream, "jpg"); } builder.InsertText("Simple sentence 2 in line"); //Add in-line image using Paragraph object Paragraph paragraph = builder.InsertParagraph(); //Add text before TextInline textStart = paragraph.Inlines.AddText(); textStart.Text = "Text add using paragraph start."; //Insert image in the middle of text content ImageInline imageInline = paragraph.Inlines.AddImageInline(); using (Stream stream = File.OpenRead("sample.png")) { imageInline.Image.ImageSource = new Basic.Media.ImageSource(stream, "png"); } //Add text after TextInline textEnd = paragraph.Inlines.AddText(); textEnd.Text = "Text add using paragraph end."; WordFile wordFile = new WordFile(); File.WriteAllBytes("AddImageInline.docx", wordFile.Export(document)); }
public static void AddTableFrame() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); builder.TableState.Indent = 100; builder.TableState.PreferredWidth = new TableWidthUnit(300); builder.TableState.LayoutType = TableLayoutType.FixedWidth; Paragraph tableTitle = builder.InsertParagraph(); tableTitle.TextAlignment = Alignment.Center; builder.InsertLine("Table Frame"); Table table = builder.InsertTable(); table = CreateTableFrame(table); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddTableFrame.docx")) { wordFile.Export(document, stream); } }
public static void AddComment() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); builder.InsertLine("First paragraph in this document."); //Insert some content before comment builder.InsertText("Second paragraph start. "); //Select the content you want to comment TextInline textComment = builder.InsertText("Text has comment. "); //Insert some content after comment builder.InsertText("Second paragraph end."); //Add comment with selected content Comment comment = builder.InsertComment("Comment details here", textComment, textComment); comment.Author = "iDiTect"; comment.Date = DateTime.Now; WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddComment.docx")) { wordFile.Export(document, stream); } }
public static void ReplaceText() { WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx")); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Replace target text in whole document, match-case and match-whole-word are supported builder.ReplaceText("Page", "as", true, true); File.WriteAllBytes("ReplaceText.docx", wordFile.Export(document)); }
public ActionResult Submit(HomePageModel model) { string saveDir = HttpContext.Server.MapPath("~/SavedData"); string stopwordPath = HttpContext.Server.MapPath("~/FileLogic/StopWords"); FileHandler fileHandler = new FileHandler(model.SomeFile, saveDir, model.IncludeStopwords); string filePathOriginal = fileHandler.GetFilePathOriginal(); WordFile fileWithWords = new WordFile(filePathOriginal, stopwordPath, model.IncludeStopwords); fileHandler.AppendPostProcessInfo(fileWithWords.GetMostFrequentWords(), model.IncludeStopwords); model.AnalaysisStates = fileHandler.GetAnalysisStates(); return(View("Index", model)); }
public static void ProtectDocument() { //Load an existing word file WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx")); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Protect file with password and permission builder.Protect("password", Protection.ProtectionMode.AllowComments); File.WriteAllBytes("Protected.docx", wordFile.Export(document)); }
public GuideWindow() { InitializeComponent( ); //设置标题 Title = titles[0]; Task = new ExcelToWordTask( ); Excel = new ExcelFile( ); wd = new WordFile( ); }
static private WordFile GetWordfile(string Filename) { WordFile theWordfile; try { theWordfile = new WordFile(Filename); } catch (Exception) { throw; } return(theWordfile); }
public static void UnprotectDocument() { //Load the protected word file WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Protected.docx")); WordDocumentBuilder builder = new WordDocumentBuilder(document); //If you have own the password, you can unprotect the document with password //builder.Unprotect("password"); //If you don't own the password, you can unprotect the document without password builder.Unprotect(); File.WriteAllBytes("Unprotected.docx", wordFile.Export(document)); }
public static void AddMailMerge() { WordDocument document = CreateMailMergeTemplate(); IEnumerable datas = CreateTestData(); WordDocument mailMergedDocument = document.MailMerge(datas); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("MailMergeData.docx")) { wordFile.Export(mailMergedDocument, stream); } }
public static void AddText() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Set global style for text and paragraph builder.CharacterState.FontFamily = new ThemableFontFamily("Arial"); builder.CharacterState.FontSize = 16; builder.ParagraphState.LineSpacing = 1.2; builder.ParagraphState.FirstLineIndent = 40; //Insert text using builder directly builder.InsertText("Nomal text. "); //Insert one line with text, it will add line break automatically builder.InsertLine("Nomal line with auto line break. "); //So the text below will be added in a second paragraph builder.InsertText("Nomal text. "); //Insert text using TextInline object TextInline textInline = new TextInline(document); textInline.Text = "This text content is using TextInline object. "; textInline.FontSize = 20; builder.InsertInline(textInline); //Insert text with customized style builder.InsertText("Times New Roman, ").FontFamily = new ThemableFontFamily("Times New Roman"); builder.InsertText("bold, ").FontWeight = FontWeights.Bold; builder.InsertText("italic, ").FontStyle = FontStyles.Italic; builder.InsertText("underline, ").Underline.Pattern = UnderlinePattern.Single; builder.InsertText("colors ").ForegroundColor = new ThemableColor(Color.FromRgb(255, 0, 0)); //Add several paragraphs to page for (int i = 0; i < 20; i++) { builder.InsertParagraph(); for (int j = 1; j < 11; j++) { builder.InsertText("This is sentence " + j.ToString() + ". "); } } WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddText.docx")) { wordFile.Export(document, stream); } }
public static void AddLinkToWebLink() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Add hyperlink to web url builder.InsertHyperlink("this is hyperlink", "http://www.iditect.com", "go to iditect site"); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddLinkToWebLink.docx")) { wordFile.Export(document, stream); } }
public static void MergeDocument() { WordFile wordFile = new WordFile(); WordDocument source = wordFile.Import(File.ReadAllBytes("source.docx")); WordDocument target = wordFile.Import(File.ReadAllBytes("target.docx")); //The source document will be appended at the end of target document //The content of source document will be started at a new page target.Merge(source); //If these two documents have the same style ID, you can choose which to use //MergeOptions options = new MergeOptions(); //options.ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.UseTargetStyle; //target.Merge(source, options); File.WriteAllBytes("Merged.docx", wordFile.Export(target)); }
public static void HighlightText() { WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx")); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Apply new highlight style Action <CharacterState> action = new Action <CharacterState>((state) => { state.HighlightColor = Colors.Yellow; }); //Highlight all the "Page" text in the document builder.ReplaceStyling("Page", true, true, action); File.WriteAllBytes("HighlightText.docx", wordFile.Export(document)); }
public static void AddFloatingImage() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); builder.CharacterState.FontSize = 24; //Add floating image using builder using (Stream stream = File.OpenRead("sample.jpg")) { FloatingImage floatingImage1 = builder.InsertFloatingImage(stream, "jpg"); floatingImage1.Wrapping.WrappingType = ShapeWrappingType.Square; } builder.InsertText("This text sentence content will display at the square of the floating image. "); builder.InsertText("This text sentence content will display at the square of the floating image."); WordFile wordFile = new WordFile(); File.WriteAllBytes("AddFloatingImage.docx", wordFile.Export(document)); }
public static void InsertDocument() { WordFile wordFile = new WordFile(); WordDocument source = wordFile.Import(File.ReadAllBytes("source.docx")); WordDocument target = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(target); builder.CharacterState.FontSize = 30; builder.InsertLine("Text start in target document."); //Insert the source document just after the first paragraph in the target document builder.InsertDocument(source); //This line will be appended tight after the source document content builder.InsertLine("Text end in target document."); File.WriteAllBytes("InsertDocument.docx", wordFile.Export(target)); }
public static void AddHeaderFooterForSections() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); //One section can contains a range of pages //Insert one section with single page Section sectionSinglePage = builder.InsertSection(); builder.InsertText("First page in section 1"); //Add header for single page section Header headerSinglePage = sectionSinglePage.Headers.Add(); headerSinglePage.Blocks.AddParagraph().Inlines.AddText("header for single page section"); //Insert one section with multiple pages Section sectionMultipage = builder.InsertSection(); //Create first page in section builder.InsertText("First page in section 2"); builder.InsertBreak(BreakType.PageBreak); //Create second page in section builder.InsertText("Second page in section 2"); //Defaults, all the secions's header and footer will inherit the rules in the first section //If you want to use blank header in the second section, you need initialize a new Header object with nothing to do Header headerMultipage = sectionMultipage.Headers.Add(); //Add footer for multiple page section Footer footerMultipage = sectionMultipage.Footers.Add(); footerMultipage.Blocks.AddParagraph().Inlines.AddText("footer for multiple page section"); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddHeaderFooterForSections.docx")) { wordFile.Export(document, stream); } }
public static void AddLinkInsideDocument() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Add hyperlink navigate to bookmark inside this document by bookmark's name builder.InsertHyperlinkToBookmark("this is hyerlink", "bookmark1", "go to bookmark1"); //Add a bookmark in the second page builder.InsertBreak(BreakType.PageBreak); TextInline textBookmark = builder.InsertText("This is bookmark1. "); builder.InsertBookmark("bookmark1", textBookmark, textBookmark); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddLinkInsideDocument.docx")) { wordFile.Export(document, stream); } }
public static void AddSimpleHeaderFooter() { WordFile wordFile = new WordFile(); WordDocument document = wordFile.Import(File.ReadAllBytes("Sample.docx")); //Add header at the left Header header = document.Sections[0].Headers.Add(); Paragraph paragraphHeader = header.Blocks.AddParagraph(); paragraphHeader.TextAlignment = Styles.Alignment.Left; paragraphHeader.Inlines.AddText("simple header"); //Add footer at the right Footer footer = document.Sections[0].Footers.Add(); Paragraph paragraphFooter = footer.Blocks.AddParagraph(); paragraphFooter.TextAlignment = Styles.Alignment.Right; paragraphFooter.Inlines.AddText("simple footer"); File.WriteAllBytes("SimpleHeaderFooter.docx", wordFile.Export(document)); }
public static void AddSimpleTable() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); builder.TableState.Indent = 100; Paragraph tableTitle = builder.InsertParagraph(); tableTitle.TextAlignment = Alignment.Center; builder.InsertLine("Simple Table Title"); Table table = builder.InsertTable(); table = CreateSimpleTable(table); WordFile wordFile = new WordFile(); using (var stream = File.OpenWrite("AddSimpleTable.docx")) { wordFile.Export(document, stream); } }
public void Publish(WordFile wordFile) { var channel = _rabbitMQClientService.Connect(); Message message = new Message(); using (MemoryStream memoryStream = new MemoryStream()) { wordFile.File.CopyTo(memoryStream); message.WordByte = memoryStream.ToArray(); } message.Email = wordFile.Email; message.FileName = Path.GetFileNameWithoutExtension(wordFile.File.FileName); var serializeMessage = JsonConvert.SerializeObject(message); var messageBody = Encoding.UTF8.GetBytes(serializeMessage); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish(RabbitMQClientService.exchangeName, RabbitMQClientService.routeKeyForPdf, properties, messageBody); channel.BasicPublish(RabbitMQClientService.exchangeName, RabbitMQClientService.routeKeyForZip, properties, messageBody); }
static void Main(string[] args) { IFile file = new WordFile(); WordFile wf = new WordFile(); file.Load(""); //file.Save("bye"); wf.Load("hi"); wf.Save("gg"); wf.Delete(); (file as WordFile).Delete(); IMailService ims = new MailService(); MailService ms = new MailService(); ims.Count = 6; ims.SendMail("h"); ms.SendMail("j"); ms.Count = 9; Console.WriteLine(ims.Count + ms.Count); Console.ReadLine(); }