WordLocalView (转)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | //http://office09.googlecode.com/svn-history/r491/trunk/OfficeInCloudWord2007/WordLocalView.cs // http://office09.googlecode.com/svn/trunk/ using System; using System.Collections; using System.Linq; using System.Text; using System.Globalization; using LocalView; using DataType; using Google.GData.Client; using Google.Contacts; using Google.Documents; using Google.GData.Documents; using System.IO; using Google.GData.AccessControl; using Word = Microsoft.Office.Interop.Word; using VSTO = Microsoft.Office.Tools.Word; using Microsoft.Office.Tools.Word.Extensions; using Utilities; using System.Xml; using System.Xml.Xsl; using System.Xml.XPath; namespace OfficeInCloudWord2007 { public class WordLocalView : ILocalView { private bool isLoggedIn; public delegate void StateNotify( string key); private global::System.Object missing = global::System.Type.Missing; public Word.Application m_App; public override event EventHandler<Credentials> Login; public override event EventHandler<FeedWrapper<Contact>> GetContacts; public override event EventHandler<FeedWrapper<Document>> GetDocuments; public override event EventHandler<FeedWrapper<Document>> GetFolders; public override event EventHandler<DocumentInfo> UploadDocument; public override event EventHandler<DocumentInfo> UpdateDocument; public override event EventHandler<DownloadInfo> DownloadDocument; public override event EventHandler<ShareInfoCollection> ShareDocument; public override event EventHandler<ShareInfoCollection> GetDocumentAcl; public override event EventHandler<DocumentInfo> LookForDocument; public override event EventHandler<DocumentInfo> OpenDocumentInCloud; public override event EventHandler<ContactInfo> AddContact; private DbOperations m_dbOperations; public StateNotify m_LoadState; public StateNotify m_StoreState; public WordLocalView(Word.Application App, DbOperations dbOperations) { m_App = App; m_DocInfo = null ; m_dbOperations = dbOperations; isLoggedIn = false ; } public override string GetDocumentPath() { return m_App.ActiveDocument.FullName; } public override string GetDocumentName() { return m_App.ActiveDocument.Name; } public override void DoLogin(Credentials cred) { if (Login != null ) Login( this , cred); isLoggedIn = true ; } public override void DoDownloadDocument(DownloadInfo info) { if (DownloadDocument != null ) DownloadDocument( this , info); } public override void DoGetContacts(FeedWrapper<Contact> feed) { if (GetContacts != null ) GetContacts( this , feed); } public void DoGetContactsAsync(NotifyDelegate<Contact> Notify) { if (GetContacts != null ) { DoIterationASync<Contact> Iteration = new DoIterationASync<Contact>( this .GetContacts, Notify, this .dummy); Iteration.StartAction(); } } public override void DoGetDocuments(FeedWrapper<Document> feed) { if (GetDocuments != null ) GetDocuments( this , feed); } public void DoGetDocumentsAsync(NotifyDelegate<Document> Notify) { if (GetDocuments != null ) { DoIterationASync<Document> Iteration = new DoIterationASync<Document>( this .GetDocuments, Notify, this .dummy); Iteration.StartAction(); } } private void saveDocument() { Word.WdAlertLevel wd = m_App.DisplayAlerts; try { m_App.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; string fname = m_App.ActiveDocument.FullName; string docName1 = m_App.ActiveDocument.Name; if (!System.IO.Path.IsPathRooted(fname)) { object path = Utilities.Path.documentPath + "\\" + m_App.ActiveDocument.FullName; m_App.ActiveDocument.SaveAs( ref path, ref missing, ref missing, //password ref missing, //writeRefPassword ref missing, //readOnlyRecommended ref missing, //createBackup ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); } else m_App.ActiveDocument.Save(); } finally { m_App.DisplayAlerts = wd; } } public override void DoSaveDocumentInCloud() { saveDocument(); if (UploadDocument != null ) { m_DocInfo = new DocumentInfo(m_App.ActiveDocument.FullName, m_App.ActiveDocument.Name); UploadDocument( this , m_DocInfo); m_dbOperations.DoRegisterLocalCopy(m_DocInfo); } } public override void Merge(Document dt, ILocalView.CollisionWinner winner) { Document.DownloadType type = Document.DownloadType.doc; DownloadInfo info = new DownloadInfo(dt, type); DownloadDocument( this , info); //get new DocumentEnty //DoLookupRemoteCopy(m_DocInfo); Word.Document localWb = m_App.ActiveDocument; string tmpPath = localWb.FullName + "_tmp.doc" ; FileInfo fileInfo = new FileInfo(tmpPath); FileStream stream = fileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); CommonOperations.DoSaveContent(stream, info.m_Stream); MergeContent(tmpPath); fileInfo.Delete(); //throw new NotImplementedException(); } private void MergeContent( string serverCopyPath) { object MergeTarget = Word.WdMergeTarget.wdMergeTargetCurrent; object DetectFormatChanges = true ; object UseFormattingFrom = Word.WdUseFormattingFrom.wdFormattingFromCurrent; object AddToRecentFiles = true ; m_App.ActiveDocument.Merge(serverCopyPath, ref MergeTarget, ref DetectFormatChanges, ref UseFormattingFrom, ref AddToRecentFiles); m_App.ActiveDocument.Save(); } public override void DoLookupRemoteCopy(DocumentInfo info) { //at first look for document id in db, if no document then exception happens m_dbOperations.DoLookupRemoteCopy(info); if (info.m_RemoteId == null ) return ; if (LookForDocument != null ) LookForDocument( this , info); } public override void DoUpdateDocument() { if (UpdateDocument != null ) { m_App.ActiveDocument.Save(); UpdateDocument( this , m_DocInfo); } //try{ // if (UpdateDocument != null) // { // m_App.ActiveDocument.Save(); // UpdateDocument(this, m_DocInfo); // } //} //catch(GDataRequestException e) //{ // //create later lookup for type depending extension using DocumentEntry.IsSpreadsheet and so on // Document.DownloadType type = Document.DownloadType.doc; // Document dt = new Document(); // dt.AtomEntry = m_DocInfo.m_DocEntry; // DownloadInfo info = new DownloadInfo(dt, type); // DownloadDocument(this, info); // //get new DocumentEnty // DoLookupRemoteCopy(m_DocInfo); // Word.Document wb = m_App.ActiveDocument; // string tmpPath = wb.Path + "\\" + wb.Name + "_tmp.doc"; // FileInfo fileInfo = new FileInfo(tmpPath); // FileStream stream = fileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); // CommonOperations.DoSaveDocumentContent(stream, info.m_Stream); // MergeDocumentWith(tmpPath); // fileInfo.Delete(); // //try to update document again // DoUpdateDocument(); //} } private void BuildListOfUsers(IEnumerable users, Permission perm, AclFeed feed) { string permStr = null ; switch (perm) { case Permission.reader: permStr = "reader" ; break ; case Permission.writer: permStr = "writer" ; break ; } foreach ( object obj in users) { AclEntry entry = new AclEntry(); entry.Scope = new AclScope(); entry.Scope.Type = AclScope.SCOPE_USER; //parse the email string value = obj.ToString(); if (value.Contains( '(' )) { value = value.Split( new char [] { '(' , ')' })[1]; } entry.Scope.Value = value; entry.Role = new AclRole(permStr); feed.Entries.Add(entry); } } private void dummy() {} private void RefreshEtag() { DoLookupRemoteCopy(m_DocInfo); } public override void UpdateDocumentInfo() { m_DocInfo = new DocumentInfo(m_App.ActiveDocument.FullName, m_App.ActiveDocument.Name); DoLookupRemoteCopy(m_DocInfo); } public override void DoShareDocumentsAsync(IEnumerable users, Permission perm) { if (ShareDocument != null ) { ShareInfoCollection info = new ShareInfoCollection(m_DocInfo.m_DocEntry); BuildListOfUsers(users, perm, info.m_Feed); DoOperationASync<ShareInfoCollection> operation = new DoOperationASync<ShareInfoCollection>( this .ShareDocument, info, this .RefreshEtag); operation.StartAction(); } } public override void DoOpenLocalCopy( string filePath) { object fileName = filePath; object readOnly = false ; object isVisible = true ; // Here is the way to handle parameters you don't care about in .NET object missing = System.Reflection.Missing.Value; try { Word.Document wb = m_App.Documents.Open( ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); wb.Save(); wb.Activate(); //m_App.ActiveDocument.TrackRevisions = true; } catch (Exception ex) { Utilities.TraceWrapper.LogException( "DoOpenLocalCopyShared error: " + ex.Message, ex); } } public override string GetInviteUri() { return m_DocInfo.m_DocEntry.AlternateUri.Content; } public override void DoOpenDocumentInCloud(DocumentInfo info) { if (OpenDocumentInCloud != null ) OpenDocumentInCloud( this , info); } public override void DoGetDocumentAcl(ShareInfoCollection info) { if (GetDocumentAcl != null ) GetDocumentAcl( this , info); } //////////////////////////////////////////////////////// // Temporary stubs /////////////////////////////////////////////////////// public override bool IsDocumentOpened( string path) { foreach (Word.Document dc in m_App.Documents) if (dc.FullName == path) return true ; return false ; } public override void CloseDocument( string path) { foreach (Word.Document dc in m_App.Documents) if (dc.FullName == path) { object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges; object route = false ; dc.Close( ref saveChanges, ref missing, ref route); } } public override void ActivateDocument( string path) { foreach (Word.Document dc in m_App.Documents) if (dc.FullName == path) dc.Activate(); } public override string SupportedFormats() { return "Word|*.doc|Word 2007|*.docx" ; } public override Document.DocumentType DocumentType() { return Document.DocumentType.Document; } public override Document.DownloadType DownloadType() { return Document.DownloadType.doc; } public override string GetContentText() { return m_App.ActiveDocument.Content.Text; } public override void SmartTagActions(Object tag) { m_App.ActiveDocument.GetVstoObject().VstoSmartTags.Add(tag as VSTO.SmartTag); m_App.ActiveDocument.RecheckSmartTags(); // m_App.ActiveDocument.GetVstoObject().SmartTags.ReloadRecognizers(); m_App.SmartTagRecognizers.ReloadRecognizers(); } public override void HighlightSmartTags( string s) { foreach (Word.Range word in m_App.ActiveDocument.Words) //If we trim, we need to highlight less than the size of the word otherwise the space after //the word is highlighted as well. if ( string .Compare(word.Text.Trim(), s, true , CultureInfo.InvariantCulture) == 0) word.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdYellow; } public override bool IsLoggedIn() { return isLoggedIn; } //this method is required since user can upload both xls, xlsx, but download only one .xls //so it's possible that downloaded .xls file but with extension .xlsx due local copy is .xlsx public override void CastContentToExtension( string docPath, Document.DownloadType type) { //it means that we downloaded xls but with extension xlsx, we need convert content to the format xlsx if ((Document.DownloadType.doc == type) && docPath.EndsWith( ".docx" )) { Word.WdAlertLevel wd = m_App.DisplayAlerts; try { m_App.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; //rename file to the correct extension string correctedPath = docPath + System.Guid.NewGuid().ToString() + ".doc" ; FileInfo ab = new FileInfo(docPath); ab.MoveTo(correctedPath); //change its format to the required object file = correctedPath; Word.Document tmp = m_App.Documents.Open( ref file, 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); object soureceFile = docPath; object format = Word.WdSaveFormat.wdFormatDocumentDefault; tmp.SaveAs( ref soureceFile, ref format, ref missing, //password ref missing, //writeRefPassword ref missing, //readOnlyRecommended ref missing, //createBackup ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); object saveChanges = Word.WdSaveOptions.wdSaveChanges; object route = false ; tmp.Close( ref saveChanges, ref missing, ref route); ab.Delete(); } catch (Exception e) { Utilities.TraceWrapper.LogException( "CastContentToExtension error: " + e.Message, e); } finally { m_App.DisplayAlerts = wd; } } } public override void InsertSearchResult( string [] result) { Word.Selection currentSelection = this .m_App.Selection; // Store the user's current Overtype selection bool userOvertype = this .m_App.Options.Overtype; // Make sure Overtype is turned off. if ( this .m_App.Options.Overtype) { this .m_App.Options.Overtype = false ; } // Test to see if selection is an insertion point. if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP) { TypeText(currentSelection, result); } else if (currentSelection.Type == Word.WdSelectionType.wdSelectionNormal) { // Move to start of selection. if ( this .m_App.Options.ReplaceSelection) { object direction = Word.WdCollapseDirection.wdCollapseStart; currentSelection.Collapse( ref direction); } TypeText(currentSelection, result); } else { // Do nothing. } // Restore the user's Overtype selection this .m_App.Options.Overtype = userOvertype; } private void TypeText(Word.Selection currentSelection, string [] results) { currentSelection.TypeText( "Title: " + results[0]); currentSelection.TypeParagraph(); currentSelection.TypeText( "Description: " ); currentSelection.TypeParagraph(); currentSelection.TypeText(results[1]); currentSelection.TypeParagraph(); currentSelection.TypeText( "Public profile: " ); object s = results[2]; m_App.ActiveDocument.Hyperlinks._Add( currentSelection.Range, ref s, ref missing ); } public override void DoAddContact(ContactInfo contact) { if (AddContact != null ) AddContact( this , contact); } static void SetHeadings(Microsoft.Office.Interop.Word.Cell tblCell, string text) { tblCell.Range.Text = text; tblCell.Range.Font.Bold = 1; tblCell.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; } public override void InsertSearchResultEx( string [] result) { Word.Selection currentSelection = this .m_App.Selection; Word.Range rng = currentSelection.Range; //VSTO.ControlCollection controls = m_App.ActiveDocument.GetVstoObject().Controls; object s = result[3]; rng.Text = result[1]; Word.Hyperlink hl = rng.Hyperlinks._Add(rng, ref s, ref missing); rng.Start = rng.End + 1; VSTO.Controls.PictureBox pb = m_App.ActiveDocument.GetVstoObject().Controls.AddPictureBox(rng, 15, 15, System.Guid.NewGuid().ToString()); /*object oType = Word.WdFieldType.wdFieldComments; //.wdFieldAddin; object oResult = ""; object oBool = true; foreach (string str in result) { oResult += str + "|"; } Word.Field fd = m_App.ActiveDocument.Fields.Add(rng, ref oType, ref oResult, ref oBool); */ pb.Image = Properties.Resources.Loop_small; pb.Tag = result; pb.MouseEnter += new EventHandler(pb_MouseEnter); pb.MouseLeave += new EventHandler(pb_MouseLeave); } public override void HighLightsTags( string [] result) { try { //VSTO.ControlCollection controls = m_App.ActiveDocument.GetVstoObject().Controls; Word.Range rng = m_App.ActiveDocument.Content; rng.Find.ClearFormatting(); object findText = result[1]; object oTrue = true ; object oFalse = false ; object oFindStop = Word.WdFindWrap.wdFindStop; int pos = rng.End; rng.Find.Execute( ref findText, ref oFalse, ref oTrue, ref oTrue, ref oFalse, ref oFalse, ref oTrue, ref oFindStop, ref oFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); while (rng.Find.Found) { object s = result[3]; Word.Hyperlink hl = rng.Hyperlinks._Add(rng, ref s, ref missing); rng.Start = rng.End + 1; VSTO.Controls.PictureBox pb = m_App.ActiveDocument.GetVstoObject().Controls.AddPictureBox(rng, 15, 15, System.Guid.NewGuid().ToString()); pb.Image = Properties.Resources.Loop_small; pb.Tag = result; pb.MouseEnter += new EventHandler(pb_MouseEnter); pb.MouseLeave += new EventHandler(pb_MouseLeave); pos = rng.End; rng = m_App.ActiveDocument.Content; rng.Start = pos + 1; rng.Find.Execute( ref findText, ref oFalse, ref oTrue, ref oTrue, ref oFalse, ref oFalse, ref oTrue, ref oFindStop, ref oFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); if (pos >= rng.Start) return ; } } catch (Exception e) { } } public override void TestAddContentcontrol( string [] results) { Word.Range rng = m_App.ActiveDocument.Content; VSTO.Controls.PictureBox pb = m_App.ActiveDocument.GetVstoObject().Controls.AddPictureBox(rng, 15, 15, "picture" ); pb.Image = Properties.Resources.Loop_small; pb.Tag = results; //pb.MouseHover += new EventHandler(lb_MouseHover); pb.MouseEnter += new EventHandler(pb_MouseEnter); pb.MouseLeave += new EventHandler(pb_MouseLeave); } private CardDialog card = new CardDialog(); private void pb_MouseEnter( object sender, EventArgs e) { //int i = 10; if (!card.Visible) { VSTO.Controls.PictureBox pb = (VSTO.Controls.PictureBox)sender; card.Width = 500; card.Height = 300; card.ControlBox = false ; card.StartPosition = System.Windows.Forms.FormStartPosition.Manual; card.Location = new System.Drawing.Point( System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y); card.lbTitle.Text = (( string [])pb.Tag)[1]; card.txtDescription.Text = (( string [])pb.Tag)[2]; card.lbWebsite.Text = (( string [])pb.Tag)[3]; card.lbCategory.Text = (( string [])pb.Tag)[0]; card.Show(); } } private void pb_MouseLeave( object sender, EventArgs e) { //int i = 10; VSTO.Controls.PictureBox pb = (VSTO.Controls.PictureBox)sender; card.Hide(); } public override string GetHTMLDocumentContent() { /* object prev_path = m_App.ActiveDocument.FullName; //Word.XMLNodes nodes = m_App.ActiveDocument.GetVstoObject().XMLNodes; object path = System.IO.Path.GetTempPath() //+ m_App.ActiveDocument.Name.Split(new char[]{'.'})[0] + Guid.NewGuid() + ".html"; object oFormat = Word.WdSaveFormat.wdFormatFilteredHTML; object oBool = true; m_App.ActiveDocument.SaveAs(ref path, ref oFormat, ref missing, //password ref missing, //writeRefPassword ref missing, //readOnlyRecommended ref missing, //createBackup ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); m_App.ActiveDocument.Close(ref oBool, ref missing, ref oBool); m_App.Documents.Open(ref prev_path, ref missing, //password ref missing, //writeRefPassword ref missing, //readOnlyRecommended ref missing, //createBackup ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); string content; using (FileStream fs = File.OpenRead((string)path)) { StreamReader rd = new StreamReader(fs, Encoding.UTF8); content = rd.ReadToEnd(); } return content; * */ /* m_App.ActiveDocument.Content.Copy(); object oDocType = Word.WdDocumentType.wdTypeDocument; object oBool = false; Word.Document doc = m_App.Documents.Add(ref missing, ref missing, ref oDocType, ref oBool); doc.Content.Paste(); object oFormat = Word.WdSaveFormat.wdFormatFilteredHTML; oBool = true; object path = System.IO.Path.GetTempPath() //+ m_App.ActiveDocument.Name.Split(new char[]{'.'})[0] + Guid.NewGuid() + ".html"; doc.SaveAs(ref path, ref oFormat, ref missing, //password ref missing, //writeRefPassword ref missing, //readOnlyRecommended ref missing, //createBackup ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc.Close(ref oBool, ref missing, ref oBool); string content; using (FileStream fs = File.OpenRead((string)path)) { StreamReader rd = new StreamReader(fs, Encoding.UTF8); content = rd.ReadToEnd(); } return content; ** */ /* Word.XMLNodes nodes = m_App.ActiveDocument.GetVstoObject().XMLNodes; XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(m_App.ActiveDocument.WordOpenXML); XslTransform transform = new XslTransform(); XmlTextReader xls = new XmlTextReader(new StringReader(Properties.Resources.OpenXML)); XsltArgumentList list = new XsltArgumentList(); StringWriter res = new StringWriter(); transform.Load(xls); XmlTextWriter wr = new XmlTextWriter(res); transform.Transform(xdoc, null, wr); wr.Close(); //return rng.WordOpenXML; //throw new NotImplementedException(); return ""; * */ string m_out = "" ; return Trafo(( string )m_App.ActiveDocument.WordOpenXML, ( string )Properties.Resources.OpenXML, out m_out); } public string Trafo( string XMLPage, string XSLStylesheet, out string ErrMsg) { //the outputs string result= "" ; ErrMsg= "" ; try { XMLPage = XMLPage.Replace( "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">" , "<Relationships>" ); //read XML TextReader tr1= new StringReader(XMLPage); XmlTextReader tr11= new XmlTextReader(tr1); XPathDocument xPathDocument= new XPathDocument(tr11); //read XSLT TextReader tr2= new StringReader(XSLStylesheet); XmlTextReader tr22= new XmlTextReader(tr2); XslTransform xslt = new XslTransform (); xslt.Load(tr22); //create the output stream StringBuilder sb= new StringBuilder(); TextWriter tw= new StringWriter(sb); //xsl.Transform (doc, null, Console.Out); xslt.Transform(xPathDocument, null ,tw); //get result result=sb.ToString(); } catch (Exception ex) { //Console.WriteLine (ex.Message); ErrMsg=ex.Message; } return result; } //Trafo public override string GetTextDocumentContent() { return m_App.ActiveDocument.Content.Text; } } } |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
分类:
CSharp code
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!