我有一个字符串,它作为WYSIWYG编辑器的输出而生成,该编辑器是具有基本64数据的HTML。样品如下。
<p>Report requires month to date and year to date <b style="background-color: rgb(255, 255, 0);">values</b> with separate debit and credit columns</p><p><br></p><p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgmOiaf+niaT+Efj//2Q==" style="width: 180px;" data-filename="8204_659888434064067_2072530899_a.jpg"><br></p><p>Figure I
</p><p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><img src="data:image/jpeg;base64,/9j/4AAQSkZQMP89aKKKAP/2Q==" data-filename="IMG-20130325-WA0000.jpg" style="box-sizing: border-box; border: 0px; vertical-align: middle; width: 168.469px; height: 137px;"><br style="box-sizing: border-box;"></p><p>Figure 2</p><p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/iigD//2Q==" style="width: 333px;" data-filename="IMG-20130906-WA0000.jpg"><br></p><p>Figure 3</p>
我删除了img标签的src数据太久了。
我需要将此字符串压入word文档。 示例代码如下
//project name
Microsoft.Office.Interop.Word.Paragraph heading = document.Content.Paragraphs.Add(ref missing);
heading.Range.set_Style(ref h1);
heading.Range.HighlightColorIndex = WdColorIndex.wdGray25;
heading.Range.Font.Color = WdColor.wdColorOrange;
heading.Range.Text = project.name + " (" + project.projectId + ") " + " - " + project.projectCode;
heading.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
heading.Range.InsertParagraphAfter();
//project details
Microsoft.Office.Interop.Word.Paragraph heading2 = document.Content.Paragraphs.Add(ref missing);
heading2.Range.set_Style(ref h2);
heading2.Range.HighlightColorIndex = WdColorIndex.wdNoHighlight;
heading2.Range.Font.Color = WdColor.wdColorBlue;
heading2.Range.Text = "Project Details:" + nextLine;
heading2.Range.Text = "Director: " + project.director.firstName + " " + project.director.lastName + " (" + project.director.email + ")" + nextLine;
heading2.Range.Text = "Manager: " + project.manager.firstName + " " + project.manager.lastName + " (" + project.manager.email + ")" + nextLine;
heading2.Range.Text = "Client: " + project.client.firstName + " " + project.client.lastName + " (" + project.client.email + ")" + nextLine;
heading2.Range.Text = "Start Date: " + project.startDate + nextLine;
heading2.Range.Text = "Expected End Date: " + project.expectedDate + nextLine;
heading2.Range.Text = "Hours: " + project.hours + nextLine;
heading2.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
heading2.Range.InsertParagraphAfter();
List<Ricefw> ricefList = context.BaseChapter.OfType<Ricefw>().Where(u => u.project.Id == project.Id && u.deleted == false).ToList();
foreach (var task in ricefList)
{
//Task Code and status
Microsoft.Office.Interop.Word.Paragraph para1 = document.Content.Paragraphs.Add(ref missing);
//para1.Range.ListFormat.ApplyBulletDefault();
para1.Range.set_Style(ref h2);
para1.Range.HighlightColorIndex = WdColorIndex.wdGray25;
para1.Range.Font.Color = WdColor.wdColorOrange;
para1.Range.Text = task.taskCode;
para1.Range.InsertParagraphAfter();
//other details
Microsoft.Office.Interop.Word.Paragraph para2 = document.Content.Paragraphs.Add(ref missing);
para2.Range.HighlightColorIndex = WdColorIndex.wdNoHighlight;
para2.Range.Font.Color = WdColor.wdColorBlack;
para2.Range.Text = "Description: " + task.description + nextLine;
para2.Range.InsertParagraphAfter();
//task strategy
Microsoft.Office.Interop.Word.Paragraph para3 = document.Content.Paragraphs.Add(ref missing);
para3.Range.HighlightColorIndex = WdColorIndex.wdNoHighlight;
para3.Range.Font.Color = WdColor.wdColorBlack;
para3.Range.Text = "Task Strategy:" + nextLine;
if (task.taskStrategy != null && task.taskStrategy.Length > 0)
{
para2.Range.Text =task.taskStrategy; //task.taskStrategy has the html with base64 embedded image
para3.Range.InsertParagraphAfter();
}
else
{
para3.Range.Text = "No Task Strategy.";
}
para3.Range.InsertParagraphAfter();
}
我尝试复制到剪贴板并粘贴,HTML正在按预期进行,但图像丢失了。
非常感谢任何帮助。