private void MoveSheetXmlNode(ExcelWorksheet sourceSheet, ExcelWorksheet targetSheet, bool placeAfter) { var sourceNode = TopNode.SelectSingleNode(string.Format("d:sheet[@sheetId = '{0}']", sourceSheet.SheetID), _namespaceManager); var targetNode = TopNode.SelectSingleNode(string.Format("d:sheet[@sheetId = '{0}']", targetSheet.SheetID), _namespaceManager); if (sourceNode == null || targetNode == null) { throw new Exception("Source SheetId and Target SheetId must be valid"); } if (placeAfter) { TopNode.InsertAfter(sourceNode, targetNode); } else { TopNode.InsertBefore(sourceNode, targetNode); } }
/// <summary> /// Insert a rich text string at the specified index. /// </summary> /// <param name="index">The zero-based index at which rich text should be inserted.</param> /// <param name="text">The text to insert.</param> /// <returns></returns> public ExcelRichText Insert(int index, string text) { ConvertRichtext(); XmlDocument doc; if (TopNode is XmlDocument) { doc = TopNode as XmlDocument; } else { doc = TopNode.OwnerDocument; } var node = doc.CreateElement("d", "r", ExcelPackage.schemaMain); if (index < _list.Count) { TopNode.InsertBefore(node, TopNode.ChildNodes[index]); } else { TopNode.AppendChild(node); } var rt = new ExcelRichText(NameSpaceManager, node, this); if (_list.Count > 0) { ExcelRichText prevItem = _list[index < _list.Count ? index : _list.Count - 1]; rt.FontName = prevItem.FontName; rt.Size = prevItem.Size; if (prevItem.Color.IsEmpty()) { rt.Color = SKColors.Black; } else { rt.Color = prevItem.Color; } rt.PreserveSpace = rt.PreserveSpace; rt.Bold = prevItem.Bold; rt.Italic = prevItem.Italic; rt.UnderLine = prevItem.UnderLine; } else if (_cells == null) { rt.FontName = "Calibri"; rt.Size = 11; } else { var style = _cells.Offset(0, 0).Style; rt.FontName = style.Font.Name; rt.Size = style.Font.Size; rt.Bold = style.Font.Bold; rt.Italic = style.Font.Italic; _cells.IsRichText = true; } rt.Text = text; rt.PreserveSpace = true; if (_cells != null) { rt.SetCallback(UpdateCells); UpdateCells(); } _list.Insert(index, rt); return(rt); }