-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
| ||
using DocumentFormat.OpenXml; | ||
using DocumentFormat.OpenXml; | ||
using DocumentFormat.OpenXml.Packaging; | ||
using DocumentFormat.OpenXml.Wordprocessing; | ||
using HAN.Services.DTOs; | ||
|
||
namespace HAN.Services.Exporters | ||
namespace HAN.Services.Exporters; | ||
|
||
public class WordExporter : FileExporter | ||
{ | ||
public class WordExporter : FileExporter | ||
public override FileDto Export(FileDto fileDto) | ||
{ | ||
public override FileDto Export(FileDto fileDto) | ||
{ | ||
ValidateFile(fileDto); | ||
|
||
var fileName = fileDto.Name.EndsWith(".docx") ? fileDto.Name : $"{fileDto.Name}.docx"; | ||
var filePath = GetExportFilePath(fileName); | ||
ValidateFile(fileDto); | ||
|
||
Console.WriteLine($"Generating Word file at: {filePath}"); | ||
using var wordDocument = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document); | ||
var mainPart = wordDocument.AddMainDocumentPart(); | ||
mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document(); | ||
var body = mainPart.Document.AppendChild(new Body()); | ||
var paragraph = body.AppendChild(new Paragraph()); | ||
var run = paragraph.AppendChild(new Run()); | ||
run.AppendChild(new Text(fileDto.Content)); | ||
var fileName = fileDto.Name.EndsWith(".docx") ? fileDto.Name : $"{fileDto.Name}.docx"; | ||
var filePath = GetExportFilePath(fileName); | ||
|
||
return fileDto; | ||
} | ||
Console.WriteLine($"Generating Word file at: {filePath}"); | ||
using var wordDocument = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document); | ||
var mainPart = wordDocument.AddMainDocumentPart(); | ||
mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document(); | ||
var body = mainPart.Document.AppendChild(new Body()); | ||
var paragraph = body.AppendChild(new Paragraph()); | ||
var run = paragraph.AppendChild(new Run()); | ||
run.AppendChild(new Text(fileDto.Content)); | ||
|
||
return fileDto; | ||
} | ||
|
||
} |