From c9c719e2229e7cd803781f1f27d01aa0db411743 Mon Sep 17 00:00:00 2001 From: Olivier Nizet Date: Sun, 13 Oct 2024 00:18:40 +0200 Subject: [PATCH] Update sample project --- examples/Demo/Program.cs | 13 ++-- examples/Demo/Resources/Demo.html | 97 ------------------------------ examples/Demo/Resources/Demo2.html | 57 ------------------ 3 files changed, 6 insertions(+), 161 deletions(-) delete mode 100644 examples/Demo/Resources/Demo.html delete mode 100644 examples/Demo/Resources/Demo2.html diff --git a/examples/Demo/Program.cs b/examples/Demo/Program.cs index 47c0124b..0620d54f 100644 --- a/examples/Demo/Program.cs +++ b/examples/Demo/Program.cs @@ -15,7 +15,7 @@ static class Program static async Task Main(string[] args) { const string filename = "test.docx"; - string html = ResourceHelper.GetString("Resources.AdvancedTable.html"); + string html = ResourceHelper.GetString("Resources.CompleteRunTest.html"); if (File.Exists(filename)) File.Delete(filename); using (MemoryStream generatedDocument = new MemoryStream()) @@ -28,8 +28,8 @@ static async Task Main(string[] args) } generatedDocument.Position = 0L; - using (WordprocessingDocument package = WordprocessingDocument.Open(generatedDocument, true)) - //using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document)) + //using (WordprocessingDocument package = WordprocessingDocument.Open(generatedDocument, true)) + using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = package.MainDocumentPart; if (mainPart == null) @@ -38,12 +38,11 @@ static async Task Main(string[] args) new Document(new Body()).Save(mainPart); } - HtmlConverter converter = new HtmlConverter(mainPart); + HtmlConverter converter = new(mainPart, new HtmlToOpenXml.IO.DefaultWebRequest(){ + BaseImageUrl = new Uri(Path.Combine(Environment.CurrentDirectory, "images")) + }); converter.RenderPreAsTable = true; - Body body = mainPart.Document.Body; - await converter.ParseBody(html); - mainPart.Document.Save(); AssertThatOpenXmlDocumentIsValid(package); } diff --git a/examples/Demo/Resources/Demo.html b/examples/Demo/Resources/Demo.html deleted file mode 100644 index 906b7e4c..00000000 --- a/examples/Demo/Resources/Demo.html +++ /dev/null @@ -1,97 +0,0 @@ - - - -
    -
  1. This is H1 -
      -
    1. This is H2
    2. -
    3. Another H2
    4. -
    -
  2. -
  3. This is another H1 -
      -
    1. This is H2
    2. -
    3. Another H2
    4. -
    -
  4. -
  5. Last H1 -
      -
    1. This is H2
    2. -
    3. Another H2
    4. -
    -
  6. -
- -
- - Looks how cool is Open Xml. - Now with HtmlToOpenXml, it nevers been so easy to convert html. -

- If you like it, add me a rating on codeplex -

-
-
public void SetContentType(System.Web.HttpRequest request, System.Web.HttpResponse response, String reportName)
-{
-	if (request.Browser.Browser.Contains("IE"))
-	{
-		// Replace the %20 to obtain a clean name when saving the file from Word.
-		encodedFilename =
-		  Uri.EscapeDataString(Path.GetFileNameWithoutExtension(encodedFilename)).Replace("%20", " ")
-			+ Path.GetExtension(encodedFilename);
-	}
-}
- -
- -

An ordered list:

-
    -
  1. Coffee
  2. -
  3. Tea
  4. -
  5. Milk -
      -
    • Coffee
    • -
    • Tea -
        -
      1. Earl Grey
      2. -
      3. Green
      4. -
      5. Rosboh
      6. -
      -
    • -
    • Milk
    • -
    -
  6. -
  7. Wine
  8. -
- -

An unordered list:

- diff --git a/examples/Demo/Resources/Demo2.html b/examples/Demo/Resources/Demo2.html deleted file mode 100644 index 50436c08..00000000 --- a/examples/Demo/Resources/Demo2.html +++ /dev/null @@ -1,57 +0,0 @@ -

$#Candidate Code#$

-

 

-

Hello dude

-bonjour je suis du texte en mauve. - - - - - - - - - - - - - - - - - - - - - - - - -
 saa fdgdfg fdg fdgfdg 
    fdg 
  fd fdggfdg  gfdgfd
- -
- - - - - - - - - - - - - - - - - - - - - - - - - -
 saa fdgdfg fdg fdgfdg 
    fdg 
  fd fdggfdg  gfdgfd
\ No newline at end of file