本文整理汇总了C#中DocumentBuilder.InsertHtml方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.InsertHtml方法的具体用法?C# DocumentBuilder.InsertHtml怎么用?C# DocumentBuilder.InsertHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.InsertHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:InsertTableFromHtml
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithTables();
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert the table from HTML. Note that AutoFitSettings does not apply to tables
// Inserted from HTML.
builder.InsertHtml("<table>" +
"<tr>" +
"<td>Row 1, Cell 1</td>" +
"<td>Row 1, Cell 2</td>" +
"</tr>" +
"<tr>" +
"<td>Row 2, Cell 2</td>" +
"<td>Row 2, Cell 2</td>" +
"</tr>" +
"</table>");
dataDir = dataDir + "DocumentBuilder.InsertTableFromHtml_out.doc";
// Save the document to disk.
doc.Save(dataDir);
// ExEnd:InsertTableFromHtml
Console.WriteLine("\nTable inserted successfully from html.\nFile saved at " + dataDir);
}
示例2: Replacing
public ReplaceAction Replacing(ReplacingArgs e)
{
//获取当前节点
var node = e.MatchNode;
//获取当前文档
Document doc = node.Document as Document;
DocumentBuilder builder = new DocumentBuilder(doc);
//将光标移动到指定节点
builder.MoveTo(node);
//插入图片
builder.InsertHtml(html);
return ReplaceAction.Replace;
}
示例3: DocumentBuilder
/// <summary>
/// This is called when merge field is actually merged with data in the document.
/// </summary>
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
// All merge fields that expect HTML data should be marked with some prefix, e.g. 'html'.
if (e.DocumentFieldName.StartsWith("html"))
{
// Insert the text for this merge field as HTML data, using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
builder.InsertHtml((string)e.FieldValue);
// The HTML text itself should not be inserted.
// We have already inserted it as an HTML.
e.Text = "";
}
}
示例4: InsertHtml
public static void InsertHtml(string dataDir)
{
// ExStart:DocumentBuilderInsertHtml
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
"<P align='right'>Paragraph right</P>" +
"<b>Implicit paragraph left</b>" +
"<div align='center'>Div center</div>" +
"<h1 align='left'>Heading 1 left.</h1>");
dataDir = dataDir + "DocumentBuilderInsertHtml_out.doc";
doc.Save(dataDir);
// ExEnd:DocumentBuilderInsertHtml
Console.WriteLine("\nHTML using DocumentBuilder inserted successfully into a document.\nFile saved at " + dataDir);
}
示例5: DocumentBuilder
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e) {
if (e.FieldValue == null) {
return;
}
if (!e.FieldValue.ToString().StartsWith("<table") && !e.FieldValue.ToString().StartsWith("<html")) {
e.Text = e.FieldValue.ToString();
return;
}
var builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
builder.InsertHtml((string)e.FieldValue);
e.Text = "";
}
示例6: btnExportToWord_Click
protected void btnExportToWord_Click(object sender, EventArgs e)
{
Int16 PK_iChuyengiaID = Int16.Parse(btnExportToWord.CommandArgument);
ChuyengiaEntity oChuyengia = ChuyengiaBRL.GetOne(PK_iChuyengiaID);
TochucchungnhanEntity oTochuc = TochucchungnhanBRL.GetOne(oChuyengia.FK_iTochucchungnhanID);
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
builder.PageSetup.Orientation = Aspose.Words.Orientation.Portrait;
builder.PageSetup.VerticalAlignment = PageVerticalAlignment.Top;
builder.Font.Size = 12;
//------------------------------
builder.StartTable(); //Tạo bảng
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 200;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertCell(); //Ô trái
builder.Font.Bold = true;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("BỘ NÔNG NGHIỆP VÀ PTNT");
builder.Writeln(oTochuc.sCoquancap);
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 250;
builder.InsertCell(); //Ô phải
builder.Font.Bold = false;
builder.Writeln("CỘNG HOÀ XÃ HỘI CHỦ NGHĨA VIỆT NAM");
builder.Writeln("Độc lập - Tự do- Hạnh phúc");
builder.InsertHtml("<hr width='40%' />");
builder.EndRow(); //Kết thúc hàng
//-------------------------------
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 410;
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertImage(oChuyengia.imAnh, 100.0, 134.0);
builder.EndRow();
//-------------------------------
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 500;
builder.InsertCell();
builder.Font.Bold = true;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("THẺ CHUYÊN GIA ĐÁNH GIÁ VietGAP");
builder.EndRow();
//-------------------------------
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 500;
builder.InsertCell();
builder.Font.Bold = false;
builder.ParagraphFormat.LineSpacing = 10.0;
builder.Writeln("\t\tHọ và tên: " + oChuyengia.sHoten);
builder.Writeln("\t\tNăm sinh: " + "");
builder.Writeln("\t\tĐơn vị công tác: " + oTochuc.sTochucchungnhan);
builder.Writeln("\t\tLĩnh vực đánh giá: " + "");
builder.Write("\t\tMã số: ");
builder.Font.Bold = true;
builder.Writeln(oChuyengia.sMaso);
builder.EndRow();
//------------------------------
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 220;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertCell(); //Ô trái
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Width = 220;
builder.InsertCell(); //Ô phải
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("... , ngày ... tháng ... năm 20..");
builder.Font.Bold = true;
builder.Writeln("Thủ trưởng đơn vị");
builder.Font.Bold = false;
builder.Font.Italic = true;
builder.Writeln("( Ký tên, đóng dấu)");
builder.EndRow(); //Kết thúc hàng
builder.EndTable(); //Kết thúc bảng
doc.Save("Thechuyengia_" + oChuyengia.sMaso + ".doc", SaveFormat.Doc, SaveType.OpenInBrowser, Response);
//Disponse
oChuyengia = null;
oTochuc = null;
}
示例7: InsertTableFromHtml
public void InsertTableFromHtml()
{
//ExStart
//ExId:InsertTableFromHtml
//ExSummary:Shows how to insert a table in a document from a string containing HTML tags.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert the table from HTML. Note that AutoFitSettings does not apply to tables
// inserted from HTML.
builder.InsertHtml("<table>" +
"<tr>" +
"<td>Row 1, Cell 1</td>" +
"<td>Row 1, Cell 2</td>" +
"</tr>" +
"<tr>" +
"<td>Row 2, Cell 2</td>" +
"<td>Row 2, Cell 2</td>" +
"</tr>" +
"</table>");
doc.Save(ExDir + "DocumentBuilder.InsertTableFromHtml Out.doc");
//ExEnd
// Verify the table was constructed properly.
Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count);
Assert.AreEqual(2, doc.GetChildNodes(NodeType.Row, true).Count);
Assert.AreEqual(4, doc.GetChildNodes(NodeType.Cell, true).Count);
}
示例8: GenerateOutPutDocument
protected void GenerateOutPutDocument(string outFileName)
{
//Open the template document
Document doc = new Document(Server.MapPath("~/App_Data/DocumentBuilderDemo.docx"));
//Once the builder is created, its cursor is positioned at the beginning of the document.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
BarCodeBuilder barCode = CreateBarCode();
builder.InsertImage(barCode.BarCodeImage);
builder.MoveToDocumentStart();
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("~/Web/Images/spring-air-logo-header.jpg"));
builder.InsertImage(image);
builder.InsertParagraph();
builder.ParagraphFormat.ClearFormatting();
builder.Font.ClearFormatting();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.ParagraphFormat.Shading.ForegroundPatternColor = System.Drawing.Color.White;
builder.ParagraphFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.ParagraphFormat.LeftIndent = ConvertUtil.InchToPoint(0.3);
builder.ParagraphFormat.SpaceBefore = 12;
builder.ParagraphFormat.SpaceAfter = 12;
builder.Font.Name = "Arial";
builder.Font.Size = 9;
builder.Write("ELECTRONIC TICKET - PASSENGER ITINERARY/RECEIPT");
builder.InsertBreak(BreakType.LineBreak);
builder.Writeln("CUSTOMER COPY - Powered by ASPOSE");
builder.ParagraphFormat.ClearFormatting();
builder.InsertHtml("<hr>");
BuildBookingTable(builder);
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.LineBreak);
builder.InsertHtml("<hr>");
builder.InsertParagraph();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.InsertImage(barCode.BarCodeImage);
doc.Save(Response, outFileName, ContentDisposition.Inline, null);
Response.End();
}
示例9: TestNodeChangingInDocument
//ExStart
//ExFor:INodeChangingCallback
//ExFor:INodeChangingCallback.NodeInserting
//ExFor:INodeChangingCallback.NodeInserted
//ExFor:INodeChangingCallback.NodeRemoving
//ExFor:INodeChangingCallback.NodeRemoved
//ExFor:NodeChangingArgs
//ExFor:NodeChangingArgs.Node
//ExFor:DocumentBase.NodeChangingCallback
//ExId:NodeChangingInDocument
//ExSummary:Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
public void TestNodeChangingInDocument()
{
// Create a blank document object
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set up and pass the object which implements the handler methods.
doc.NodeChangingCallback = new HandleNodeChanging_FontChanger();
// Insert sample HTML content
builder.InsertHtml("<p>Hello World</p>");
doc.Save(MyDir + "Document.FontChanger Out.doc");
// Check that the inserted content has the correct formatting
Run run = (Run)doc.GetChild(NodeType.Run, 0, true);
Assert.AreEqual(24.0, run.Font.Size);
Assert.AreEqual("Arial", run.Font.Name);
}
示例10: InsertHtml
public void InsertHtml()
{
//ExStart
//ExFor:DocumentBuilder
//ExFor:DocumentBuilder.InsertHtml(string)
//ExId:DocumentBuilderInsertHtml
//ExSummary:Inserts HTML into a document. The formatting specified in the HTML is applied.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
"<P align='right'>Paragraph right</P>" +
"<b>Implicit paragraph left</b>" +
"<div align='center'>Div center</div>" +
"<h1 align='left'>Heading 1 left.</h1>");
doc.Save(MyDir + "DocumentBuilder.InsertHtml Out.doc");
//ExEnd
}
示例11: BTN_Generate_Click
protected void BTN_Generate_Click(object sender, EventArgs e)
{
try
{
if (ValidateFields())
{
string Action = DDL_Action.SelectedValue;
string Format = DDL_FileFormat.SelectedValue.ToLower();
string FileName = TXT_FileName.Text;
Entity Email = Service.Retrieve("email", EntityId, new ColumnSet(true));
string EmailBody = Email.Contains("description") ? Email["description"].ToString() : "";
string UpdatedEmailBody = ReplaceImagesInBody(EmailBody);
DocumentBuilder MyDoc = new DocumentBuilder();
MyDoc.InsertHtml(UpdatedEmailBody);
Document doc = MyDoc.Document;
MemoryStream UpdateDoc = new MemoryStream();
switch (Format.ToLower())
{
case "bmp":
doc.Save(UpdateDoc, SaveFormat.Bmp);
break;
case "doc":
doc.Save(UpdateDoc, SaveFormat.Doc);
break;
case "docx":
doc.Save(UpdateDoc, SaveFormat.Docx);
break;
case "html":
doc.Save(UpdateDoc, SaveFormat.Html);
break;
case "jpeg":
doc.Save(UpdateDoc, SaveFormat.Jpeg);
break;
case "pdf":
doc.Save(UpdateDoc, SaveFormat.Pdf);
break;
case "png":
doc.Save(UpdateDoc, SaveFormat.Png);
break;
case "rtf":
doc.Save(UpdateDoc, SaveFormat.Rtf);
break;
case "text":
case "txt":
doc.Save(UpdateDoc, SaveFormat.Text);
break;
default:
doc.Save(UpdateDoc, SaveFormat.Docx);
break;
}
if (Action == "Download")
{
Response.Clear();
Response.ContentType = "Application/msword";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "." + Format);
Response.BinaryWrite(UpdateDoc.ToArray());
// myMemoryStream.WriteTo(Response.OutputStream); //works too
Response.Flush();
Response.Close();
Response.End();
}
if (Action == "Attach to This Email")
{
if (((OptionSetValue)Email["statecode"]).Value == 1)
{
LBL_Message.Text = "Email is closed, Download the File instead";
Response.Clear();
Response.ContentType = "Application/msword";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "." + Format);
Response.BinaryWrite(UpdateDoc.ToArray());
// myMemoryStream.WriteTo(Response.OutputStream); //works too
Response.Flush();
Response.Close();
Response.End();
}
else
{
Entity NewNote = new Entity("activitymimeattachment");
byte[] byteData = UpdateDoc.ToArray();
// Encode the data using base64.
string encodedData = System.Convert.ToBase64String(byteData);
// Im going to add Note to entity
NewNote.Attributes.Add("objectid", new EntityReference("email", EntityId));
NewNote.Attributes.Add("objecttypecode", "email");
NewNote.Attributes.Add("subject", FileName + "." + Format);
// Set EncodedData to Document Body
NewNote.Attributes.Add("body", encodedData);
// Set the type of attachment
NewNote.Attributes.Add("mimetype", @"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
//NewNote.Attributes.Add("notetext", FileName);
// Set the File Name
NewNote.Attributes.Add("filename", FileName + "." + Format);
//.........这里部分代码省略.........
示例12: InsertHtml
public void InsertHtml()
{
//ExStart
//ExFor:DocumentBuilder
//ExFor:DocumentBuilder.InsertHtml
//ExId:DocumentBuilderInsertHtml
//ExSummary:Inserts HTML into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(
"<P align='right'>Paragraph right</P>" +
"<b>Implicit paragraph left</b>" +
"<div align='center'>Div center</div>" +
"<h1 align='left'>Heading 1 left.</h1>");
doc.Save(MyDir + "DocumentBuilder.InsertHtml Out.doc");
//ExEnd
}
示例13: InsertMathMl
public void InsertMathMl()
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
const string MathMl = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><msub><mi>a</mi><mrow><mn>1</mn></mrow></msub><mo>+</mo><msub><mi>b</mi><mrow><mn>1</mn></mrow></msub></mrow></math>";
builder.InsertHtml(MathMl);
doc.Save(MyDir + "MathML.docx");
doc.Save(MyDir + "MathML.pdf");
}
示例14: InsertHtmlEx
public void InsertHtmlEx()
{
//ExStart
//ExFor:DocumentBuilder.InsertHtml(String, Boolean)
//ExSummary:Inserts HTML into a document using. The current document formatting at the insertion position is applied to the inserted text.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
bool useBuilderFormatting = true;
builder.InsertHtml(
"<P align='right'>Paragraph right</P>" +
"<b>Implicit paragraph left</b>" +
"<div align='center'>Div center</div>" +
"<h1 align='left'>Heading 1 left.</h1>", useBuilderFormatting);
doc.Save(MyDir + @"\Artifacts\DocumentBuilder.InsertHtml.doc");
//ExEnd
}
示例15: DocumentBuilder
/// <summary>
/// NOTE: This is a simplistic method that will only work well when the match
/// starts at the beginning of a run.
/// </summary>
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
DocumentBuilder builder = new DocumentBuilder((Aspose.Words.Document)e.MatchNode.Document);
builder.MoveTo(e.MatchNode);
// Replace '<CustomerName>' text with a red bold name.
builder.InsertHtml("<b><font color='red'>James Bond</font></b>");
e.Replacement = "";
return ReplaceAction.Replace;
}