c# - How to store formatted snippets of Microsoft Word documents in sql server -
i need extract formatted text snippets of word document , store inside sql server table, later processing , reinsertion in word document using c#.
i've had @ word dom , seems need use combination of document.load(), document.save() , range.copy(), range.paste() methods create file each snippets load db.
isn't there easier (more efficient way)?
by way code snippets can hidden text , thinking storing snippets rtf.
finally got use aspose.words .net extract code snippets word file i'm interested in , store them rtf:
// insteresting code snippets (in case text runs // style "tw4winmark") document sourcedocument = new document(filename); var runs = sourcedocument.getchildnodes(nodetype.run, true) .select(r => r.font.stylename == "tw4winmark").tolist(); // store snippets temporary document // read aspose documentation details document document = new document(); if (runs.count > 0) { nodeimporter nodeimporter = new nodeimporter( runs[0].document, document, importformatmode.keepsourceformatting ); foreach (run run in runs) { run importedrun = nodeimporter.importnode(run, true) run; importedrun.font.hidden = false; document.sections[0].body.paragraphs[0].appendchild(importedrun); } } // save temporary document in memorystream rtf rtfsaveoptions saveoptions = new rtfsaveoptions(); memorystream ms = new memorystream(); document.save(ms, saveoptions); // retrieve rtf memorystream ms.seek(0, seekorigin.begin); streamreader sr = new streamreader(ms); string rtf = sr.readtoend();
one can store rtf text field of database usual , edit in rtf text control.
Comments
Post a Comment