Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.IO;
  3. using Foundation;
  4. using UIKit;
  5. namespace DocX.iOS.Test
  6. {
  7. [Register ("App")]
  8. public class App : UIApplicationDelegate
  9. {
  10. // Main
  11. private static void Main (string[] args)
  12. {
  13. UIApplication.Main (args, null, "App");
  14. }
  15. // constants
  16. private const string messageFormat = @"
  17. <html>
  18. <head>
  19. <style type='text/css'>
  20. html, body
  21. {{
  22. margin: 0;
  23. padding: 0;
  24. border: 0;
  25. font-size: 100%;
  26. font: inherit;
  27. font-family: Arial;
  28. vertical-align: baseline;
  29. color: #666666;
  30. }}
  31. body
  32. {{
  33. padding: 2em 2em;
  34. }}
  35. pre
  36. {{
  37. white-space: pre-wrap;
  38. }}
  39. </style>
  40. </head>
  41. <body>
  42. <h2>{0}</h2>
  43. <pre><code>{1}</code></pre>
  44. </body>
  45. </html>
  46. ";
  47. // publics
  48. public override UIWindow Window { get; set; }
  49. // FinishedLaunching
  50. public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
  51. {
  52. // create webview + controller
  53. var controller = new UIViewController ();
  54. controller.Title = "DocX - Test";
  55. var webview = new UIWebView (controller.View.Frame);
  56. webview.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
  57. webview.ScalesPageToFit = true;
  58. controller.View.AddSubview (webview);
  59. // create navigation controller
  60. var navigation = new UINavigationController (controller);
  61. // initialize window
  62. this.Window = new UIWindow (UIScreen.MainScreen.Bounds);
  63. this.Window.RootViewController = navigation;
  64. this.Window.MakeKeyAndVisible ();
  65. //
  66. try
  67. {
  68. // path to our temp docx file
  69. string pathDocx = Path.Combine(Path.GetTempPath (), "Document.docx");
  70. // inform user of what we are about to do
  71. webview.LoadHtmlString (string.Format(messageFormat, "Generating .docx file, please wait...", pathDocx), null);
  72. // generating docx
  73. using (var document = Novacode.DocX.Create (pathDocx))
  74. {
  75. Novacode.Paragraph p = document.InsertParagraph();
  76. p.Append("This is a Word Document");
  77. p = document.InsertParagraph();
  78. p.Append("");
  79. p = document.InsertParagraph();
  80. p.Append("Hello World");
  81. document.Save();
  82. }
  83. // showing docx in webview, with delay, otherwise we don't see our initial message
  84. this.Invoke(() => {
  85. webview.LoadRequest (NSUrlRequest.FromUrl (NSUrl.FromFilename (pathDocx)));
  86. }, 2.0f);
  87. // done
  88. }
  89. catch (Exception e)
  90. {
  91. webview.LoadHtmlString (string.Format(messageFormat, "Exception Occurred :", e), null);
  92. }
  93. // done
  94. return true;
  95. }
  96. }
  97. }