/// <summary> /// 去掉换行符 /// </summary> /// <param name="str"></param> /// <returns></returns> static public string RemoveReturn(string str) { return(StringTools.Replace(str, "\r\n|\r|\n", "")); }
/// <summary> /// 获得扩展名 /// </summary> /// <param name="str"></param> /// <returns></returns> static public string GetExName(string str) { string rexStr = @"(?<=\\[^\\]+.)[^\\.]+$|(?<=/[^/]+.)[^/.]+$"; return(StringTools.GetFirstMatch(str, rexStr)); }
/// <summary> /// 获得文件名 /// </summary> /// <param name="str"></param> /// <returns></returns> static public string GetFileName(string str) { string rexStr = @"(?<=\\)[^\\]+$|(?<=/)[^/]+$"; return(StringTools.GetFirstMatch(str, rexStr)); }
/// <summary> /// 获得表名 /// </summary> /// <param name="str"></param> /// <returns></returns> static public string GetTableName(string str) { string rexStr = @"(?<=\\)[^\\\.]+(?=\.)"; return(StringTools.GetFirstMatch(str, rexStr)); }
/// <summary> /// 获得包名 /// </summary> /// <param name="str"></param> /// <returns></returns> static public string GetPackName(string str) { string rexStr = @"(?<=\\)[^\\\.]+$"; return(StringTools.GetFirstMatch(str, rexStr)); }
static private List <List <string> > GetSheetContents(SpreadsheetDocument xlDoc, sheetNameData nameData) { XmlDocument sheetDoc = new XmlDocument(); sheetDoc.Load(xlDoc.WorkbookPart.GetPartById(nameData.rid).GetStream()); XmlNode sheetSize = null; XmlNode sheetData = null; XmlNode sheetRoot = null; XmlNodeList nodeList = sheetDoc.ChildNodes; foreach (XmlNode node in nodeList) { if (node.LocalName == "worksheet") { sheetRoot = node; break; } } if (sheetRoot == null) { return(null); } nodeList = sheetRoot.ChildNodes; foreach (XmlNode node in nodeList) { if (node.LocalName == "dimension") { sheetSize = node; } if (node.LocalName == "sheetData") { sheetData = node; } } if (sheetSize == null || sheetData == null) { return(null); } XmlElement sheetSizeElement = (XmlElement)sheetSize; string refStr = sheetSizeElement.GetAttribute("ref").ToString(); if (string.IsNullOrEmpty(refStr)) { return(null); } string sizeStr = StringTools.GetFirstMatch(refStr, "(?<=:)[^:]+"); if (string.IsNullOrEmpty(sizeStr)) { return(null); } string rowStr = StringTools.GetFirstMatch(sizeStr, "[a-z,A-Z]+"); int rowSize = GetRealNum(rowStr); int lineSize = int.Parse(StringTools.GetFirstMatch(sizeStr, "[0-9]+")); NameTable nt = new NameTable(); XmlNamespaceManager nsManager = new XmlNamespaceManager(nt); nsManager.AddNamespace("d", worksheetSchema); nsManager.AddNamespace("s", sharedStringSchema); List <List <string> > sData = new List <List <string> >(); for (int i = 0; i < lineSize; i++) { List <string> lineData = new List <string>(); for (int j = 0; j < rowSize; j++) { lineData.Add(GetCellValue(sheetDoc, nsManager, nt, xlDoc, j, i + 1)); } sData.Add(lineData); } return(sData); }