void CreateFloatPartDom(HtmlDocument htmldoc) { _div_glassCover = htmldoc.CreateHtmlDiv(); _div_glassCover.SetStyleAttribute("position:absolute;width:100%;height:100%;"); //--------------------------------------- //create shadow element for floating part _div_floatingPart_shadow = htmldoc.CreateHtmlDiv(); _div_floatingPart_shadow.SetStyleAttribute("background-color:rgba(0,0,0,0.2);position:absolute;left:0px;top:0px;width:300px;height:500px;"); _div_glassCover.AddChild(_div_floatingPart_shadow); //--------------------------------------- _div_floatingPart = htmldoc.CreateHtmlDiv(); _div_floatingPart.SetStyleAttribute("background-color:white;position:absolute;left:0px;top:0px;width:300px;height:500px;"); if (_items != null) { int j = _items.Count; for (int i = 0; i < j; ++i) { _div_floatingPart.AddChild(_items[i]); } _div_glassCover.AddChild(_div_floatingPart); _div_glassCover.AttachMouseDownEvent(e => { //when click on cover glass CloseHinge(); }); } }
public DomElement GetPageBody(DomElement hostNode) { if (_contentNode != null) { return(_contentNode); } HtmlDocument ownerdoc = (HtmlDocument)hostNode.OwnerDocument; _contentNode = ownerdoc.CreateHtmlDiv(); if (_contentUI != null) { //add content ui to the body of page //creat html wrapper for this ... // throw new NotImplementedException(); //reimpl here again LayoutFarm.Composers.HtmlDocument htmldoc = (LayoutFarm.Composers.HtmlDocument)ownerdoc; var wrapperElement = htmldoc.CreateWrapperElement("x", (RootGraphic rootgfx, out RenderElement renderE, out object controller) => { renderE = _contentUI.GetPrimaryRenderElement(rootgfx); controller = _contentUI; }); _contentNode.AddChild(wrapperElement); } return(_contentNode); }
public static string ToHtml(this ExcelWorksheet sheet) { int lastRow = sheet.Dimension.Rows; int lastCol = sheet.Dimension.Columns; HtmlElement htmlTable = new HtmlElement("table"); htmlTable.Attributes["cellspacing"] = 0; htmlTable.Styles["white-space"] = "nowrap"; //render rows for (int row = 1; row <= lastRow; row++) { ExcelRow excelRow = sheet.Row(row); var test = excelRow.Style; HtmlElement htmlRow = htmlTable.AddChild("tr"); htmlRow.Styles.Update(excelRow.ToCss()); for (int col = 1; col <= lastCol; col++) { ExcelRange excelCell = sheet.Cells[row, col]; HtmlElement htmlCell = htmlRow.AddChild("td"); htmlCell.Content = excelCell.Text; htmlCell.Styles.Update(excelCell.ToCss()); } } return(htmlTable.ToString()); }
public void AddItem(ListItem ui) { _items.Add(ui); if (_pnode != null) { _pnode.AddChild(ui.GetPresentationNode(_pnode)); } }
/// <summary> /// Creates a builder for the modal header. /// </summary> /// <returns>Builder for the modal body</returns> public HeaderBuilder Header(string clickAction = "cancel()") { var div = new HtmlElement(HtmlTag.Div, HtmlAttr.Class, BsClass.Modal.Header); var button = new HtmlElement(HtmlTag.Button, HtmlAttr.Class, BsClass.Modal.CloseButton, AriaAttr.Hidden, "true", NgTag.NgClick, clickAction); button.Text("\u00D7"); div.AddChild(button); return(new HeaderBuilder(HtmlHelper, div)); }
public void AddItem(DomElement item) { if (_items == null) { _items = new List <DomElement>(); } item.AttachMouseDownEvent(ItemSelected); _items.Add(item); // // if (_div_floatingPart != null) { _div_floatingPart.AddChild(item); } }
public void Expand() { if (_isOpen) { return; } _isOpen = true; if (_nodeBody != null) { if (_nodeBody.ParentNode == null) { _pnode.AddChild(_nodeBody); } } //this.TreeView.PerformContentLayout(); }
public override HtmlElement GetPresentationDomNode(Composers.HtmlElement orgDomElem) { if (_pnode != null) { return(_pnode); } //create primary presentation node _pnode = orgDomElem.OwnerHtmlDoc.CreateHtmlDiv(); _pnode.SetStyleAttribute("font:10pt tahoma"); int j = _treeNodes.Count; for (int i = 0; i < j; ++i) { _pnode.AddChild(_treeNodes[i].GetPrimaryPresentationNode(_pnode)); } return(_pnode); }
public override HtmlElement GetPresentationDomNode(Composers.HtmlElement orgDomElem) { if (_pnode != null) { return(_pnode); } //-------------------------------- _pnode = orgDomElem.OwnerHtmlDoc.CreateHtmlDiv(); _pnode.SetStyleAttribute("font:10pt tahoma;overflow:scroll;height:300px;"); int j = _items.Count; if (j > 0) { for (int i = 0; i < j; ++i) { //itemnode _pnode.AddChild(_items[i].GetPresentationNode(_pnode)); } } return(_pnode); }
public void AddChildNode(TreeNode treeNode) { if (_childNodes == null) { _childNodes = new List <TreeNode>(); } _childNodes.Add(treeNode); treeNode._parentNode = this; //--------------------------- //add treenode presentaion if (_isOpen) { if (_nodeContent != null) { //add child presentation _nodeContent.AddChild( treeNode.GetPrimaryPresentationNode(_nodeContent)); } } //--------------------------- }
public HtmlElement HandleTable(Table t, ConvertConfig conConfig) { HtmlElement table = new HtmlElement("table"); var trs = t.Elements <TableRow>(); foreach (TableRow tr in trs) { HtmlElement hTr = new HtmlElement("tr"); var tcs = tr.Elements <TableCell>(); foreach (TableCell tc in tcs) { HtmlElement hTd = new HtmlElement("td"); var pars = tc.Elements <Paragraph>(); foreach (Paragraph p in pars) { hTd.AddChild(this.HandleParagraph(p, conConfig)); } hTr.AddChild(hTd); } table.AddChild(hTr); } return(table); }
public HtmlElement HandleParagraph(Paragraph p, ConvertConfig conConfig) { HtmlElement pa = new HtmlElement("p"); OpenXmlHelper helper = new OpenXmlHelper(); StyleConfig config = new StyleConfig { Charset = "EastAsia" }; #region Paragraph var pClass = ""; if (p.ParagraphProperties != null) { var pPr = p.ParagraphProperties; pa.AddStyle(helper.GetStyleFromParagraphProperties(pPr, config)); if (pPr.ParagraphStyleId != null) { var id = pPr.ParagraphStyleId.Val; pClass += "Inner_P_" + id; } } pa.AddAttribute("class", pClass); //div.AddChild(_pa); var runs = p.Elements <Run>(); foreach (var r in runs) { var span = new HtmlElement("span"); var rpr = r.RunProperties; config.Charset = "EastAsia"; var tt = r.InnerText; Regex reg = new Regex("[\x00-\xff]{1,}", RegexOptions.IgnoreCase | RegexOptions.Multiline); var mc = reg.Match(tt); if (mc.Success) { config.Charset = "Ascii"; } span.AddStyle(helper.GetStyleFromRunProperties(rpr, config)); if (r.RunProperties != null && r.RunProperties.RunStyle != null && r.RunProperties.RunStyle.Val != null) { var id = r.RunProperties.RunStyle.Val; span.AddAttribute("class", "Inner_P_" + id + " " + "Inner_R_" + id); } var ts = r.Elements <Text>(); var pics = r.Elements <Drawing>(); foreach (Text t in ts) { span.AddChild(new HtmlElement("span", t.InnerText)); } foreach (Drawing d in pics) { DocumentFormat.OpenXml.Drawing.GraphicData gd = d.Inline.Graphic.GraphicData; var pic = gd.Elements <DocumentFormat.OpenXml.Drawing.Pictures.Picture>().ElementAt(0); var pb = pic.BlipFill; var blip = pb.Blip; var ppp = blip.Embed.Value; //var path = doc.GetReferenceRelationship(ppp).Uri; //var relationships = doc.Package.GetRelationships(); //content += ppp; var imgp = this._mainPart.GetPartById(ppp); var img = new HtmlElement("img"); //img.AddAttribute("src", imgp.Uri.ToString().Replace("/word/", "./")); img.AddAttribute("src", conConfig.ResourcePath + imgp.Uri.ToString().Substring(1)); span.AddChild(img); } pa.AddChild(span); } #endregion return(pa); }
static void Main(string[] args) { string file = "./data/word.docx"; file = "./data/DirectX_9_3D.docx"; const string ROOT = "./OUT/"; string fileMd5 = Utities.GetMd5(Path.GetFileName(file)); string docRoot = Path.Combine(new[] { ROOT, fileMd5 + "/" }); ConvertConfig config = new ConvertConfig { ResourcePath = "./" + fileMd5 + "/" }; if (!Directory.Exists(docRoot)) { Console.WriteLine("Unzip File"); UnZip un = new UnZip(); un.UnZipToDir(file, docRoot); } Console.WriteLine("Convert Word to Html"); OpenXmlHelper helper = new OpenXmlHelper(); Html.Html html = new Html.Html(); HtmlElement meta0 = new HtmlElement("meta", false); meta0.AddAttribute("http-equiv", "X-UA-Compatible"); meta0.AddAttribute("content", "IE=edge,chrome=1"); HtmlElement meta1 = new HtmlElement("meta", false); meta1.AddAttribute("name", "viewport"); meta1.AddAttribute("content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"); HtmlElement meta2 = new HtmlElement("meta", false); meta2.AddAttribute("name", "apple-mobile-web-app-capable"); meta2.AddAttribute("content", "yes"); HtmlElement meta3 = new HtmlElement("meta", false); meta3.AddAttribute("http-equiv", "content-type"); meta3.AddAttribute("content", "text/html; charset=UTF-8"); html.AddHeadElement(meta0); html.AddHeadElement(meta1); html.AddHeadElement(meta2); html.AddHeadElement(meta3); CSS css = new CSS(); CssStyle body = new CssStyle("body"); body.AddStyle("background-color", "gray"); CssStyle center = new CssStyle(".center"); center.AddStyle("text-align", "center"); css.AddStyle(body); //css.AddStyle(center); html.AddStyle(css); HtmlElement div = new HtmlElement("div"); HtmlAttribute divClass = new HtmlAttribute("class", "documentbody"); div.AddAttribute(divClass); CssStyle divStyle = new CssStyle(); divStyle.AddStyle("font-family", "'Times New Roman' 宋体"); divStyle.AddStyle("font-size", "10.5pt"); divStyle.AddStyle("margin", "0 auto"); divStyle.AddStyle("width", "600px"); divStyle.AddStyle("padding", "100px 120px"); divStyle.AddStyle("border", "2px solid gray"); divStyle.AddStyle("background-color", "white"); div.AddStyle(divStyle); #region docuemnt WordprocessingDocument doc = WordprocessingDocument.Open(file, false); //StyleParts StylesPart docstyles = doc.MainDocumentPart.StyleDefinitionsPart == null ? doc.MainDocumentPart.StylesWithEffectsPart : (StylesPart)doc.MainDocumentPart.StyleDefinitionsPart; var styles = docstyles.Styles; //styles var styleEl = styles.Elements <Style>(); //var i = __styles.Count(); //生产Style模版对应的CSS Style html.AddStyle(helper.GetStyles(styleEl)); var pps = doc.MainDocumentPart.Document.Body.ChildElements; ElementHandler handler = new ElementHandler(doc); //处理各个Word元素 foreach (var pp in pps) { //Console.WriteLine(pp.GetType().ToString()); div.AddChild(handler.Handle(pp, config)); } #endregion html.AddElement(div); string htmlfile = ROOT + fileMd5 + ".html"; FileStream fs = File.Exists(htmlfile) ? new FileStream(htmlfile, FileMode.Truncate, FileAccess.Write) : new FileStream(htmlfile, FileMode.CreateNew, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(html.ToString()); sw.Close(); fs.Close(); //// //XDocument _styles = null; //if (docstyles != null) //{ // using (var reader = XmlReader.Create(docstyles.GetStream(FileMode.Open, FileAccess.Read))) // { // _styles = XDocument.Load(reader); // } //} //if (_styles != null) //{ // //Console.WriteLine(_styles.ToString()); //} }
public static string ToHtml(this ExcelWorksheet sheet, ExcelAddress exportAddressRange = null) { int lastRow = sheet.Dimension.Rows; int lastCol = sheet.Dimension.Columns; int startRow = 1; int startColumn = 1; //cache what cells we have processed on the merge List <(int row, int col)> cache = new List <(int, int)>(); if (exportAddressRange != null) { startColumn = exportAddressRange.Start.Column; startRow = exportAddressRange.Start.Row; lastCol = exportAddressRange.End.Column; lastRow = exportAddressRange.End.Row; } HtmlElement htmlTable = new HtmlElement("table"); htmlTable.Attributes["cellspacing"] = 0; htmlTable.Styles["white-space"] = "nowrap"; htmlTable.Styles["table-layout"] = "auto"; //render rows for (int row = startRow; row <= lastRow; row++) { ExcelRow excelRow = sheet.Row(row); HtmlElement htmlRow = htmlTable.AddChild("tr"); htmlRow.Styles.Update(excelRow.ToCss()); for (int col = startColumn; col <= lastCol; col++) { ExcelRange excelCell = sheet.Cells[row, col]; HtmlElement htmlCell = null; if (sheet.Column(col).Width == 0 || sheet.Column(col).Hidden) { continue; } if (!cache.Any(c => c.row == row && c.col == col)) { htmlCell = htmlRow.AddChild("td"); } //once we find a cell thats merged, we will have to iterate through the cells until we find the end if (excelCell.Merge && !cache.Any(c => c.row == row && c.col == col)) { var currentCellColumn = excelCell.Columns; var currentCellRow = excelCell.Rows; int mergeColumnSize = 1; int mergeRowSize = 1; int lastMergedColumn = currentCellColumn; cache.Add((currentCellRow, currentCellColumn)); //start at the next column and keep going until we find the last merged column for (int i = currentCellColumn + 1; i < sheet.Dimension.Columns + 1; i++) { if (sheet.Cells[excelCell.Rows, i].Merge) { mergeColumnSize++; lastMergedColumn = i; cache.Add((excelCell.Rows, i)); } else { //merge has ended. leave the loop break; } } //since the merged cells are always a box shape, start at the column were the merge ended and go down the rows until we hit the end of the merge for (int i = currentCellRow + 1; i < sheet.Dimension.Rows + 1; i++) { if (sheet.Cells[i, lastMergedColumn].Merge) { mergeRowSize++; //add all the merged columns in the row for (int j = excelCell.Columns; j < lastMergedColumn; j++) { cache.Add((i, j)); } } else { //merge has ended. leave the loop break; } } if (mergeColumnSize > 1) { htmlCell.Attributes["colspan"] = mergeColumnSize.ToString(); } if (mergeRowSize > 1) { htmlCell.Attributes["rowspan"] = mergeRowSize.ToString(); } //skip the merged cells since they are technically empty cells } if (htmlCell != null) { htmlCell.Content = excelCell.Text; htmlCell.Styles.Update(excelCell.ToCss()); } } } return(htmlTable.ToString()); }