Java Code Examples for org.hy.common.StringHelp#replaceAll()
The following examples show how to use
org.hy.common.StringHelp#replaceAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Job.java From hy.common.tpool with Apache License 2.0 | 6 votes |
/** * 设置:允许执行的条件。 * * 表达式中,预定义占位符有(占位符不区分大小写): * :Y 表示年份 * :M 表示月份 * :D 表示天 * :H 表示小时(24小时制) * :MI 表示分钟 * :S 表示秒 * :YMD 表示年月日,格式为YYYYMMDD 样式的整数类型。整数类型是为了方便比较 * * @param i_Condition */ public void setCondition(String i_Condition) { this.condition = Help.NVL(i_Condition).toUpperCase(); this.condition = StringHelp.replaceAll(this.condition ,new String[]{ ":" + $Condition_YMD ,":" + $Condition_S ,":" + $Condition_MI ,":" + $Condition_H ,":" + $Condition_D ,":" + $Condition_D ,":" + $Condition_Y } ,new String[]{ $Condition_YMD ,$Condition_S ,$Condition_MI ,$Condition_H ,$Condition_D ,$Condition_M ,$Condition_Y }); }
Example 2
Source File: Job.java From hy.common.tpool with Apache License 2.0 | 5 votes |
/** * 设置:云计算服务器的地址端口。格式为:IP:Port。 * * 默认端口是:1721 * * @param i_CloudServer */ public void setCloudServer(String i_CloudServer) { if ( Help.isNull(i_CloudServer) ) { this.cloudSocket = null; this.cloudServer = null; return; } this.cloudServer = StringHelp.replaceAll(i_CloudServer ,new String[]{"," ," " ,"\t" ,"\r" ,"\n"} ,new String[]{"," ,""}); String [] v_HostPort = (this.cloudServer.trim() + ":1721").split(":"); this.cloudSocket = new ClientSocket(v_HostPort[0] ,Integer.parseInt(v_HostPort[1])); }
Example 3
Source File: ExcelFormula.java From hy.common.report with Apache License 2.0 | 5 votes |
/** * 计算Excel公式在偏移量(偏移多少行、偏移多少列)后新的Excel公式。 * * Excel公式中涉及到的所有单元格ID均将偏移。 * * 如,= A1 + B1 偏移1行为: = A2 + B2 * 如,= $A1 + B1 偏移1列为: = $A1 + C1 * 如,= $A$1 + B1 偏移1行1列为:= $A$1 + C2 * * @author ZhengWei(HY) * @createDate 2020-05-21 * @version v1.0 * * @param i_Formula Excle公式。 * @param i_OffsetRow 偏移多少行。零值,表示不偏移;负值向i_CellExcelID上方偏移;正值向i_CellExcelID下方偏移。 * @param i_OffsetCol 偏移多少列。零值,表示不偏移;负值向i_CellExcelID左方偏移;正值向i_CellExcelID右方偏移。 * @return */ public static String calcFormulaOffset(String i_Formula ,int i_OffsetRow ,int i_OffsetCol) { if ( Help.isNull(i_Formula) ) { return i_Formula; } String v_Formula = i_Formula.trim().toUpperCase(); String [] v_CellExcelIDOld = parserFormula(v_Formula); if ( Help.isNull(v_CellExcelIDOld) ) { return i_Formula; } String [] v_CellExcelIDPK = new String[v_CellExcelIDOld.length]; // 防止多次替换时的误替换 String [] v_CellExcelIDNew = new String[v_CellExcelIDOld.length]; // 偏移后的单元格ID for (int i=0; i<v_CellExcelIDOld.length; i++) { if ( v_CellExcelIDOld[i].startsWith("$") ) { v_CellExcelIDPK[i] = v_CellExcelIDOld[i].substring(0 ,2) + $ParserFormulaSplit + v_CellExcelIDOld[i].substring(2); } else { v_CellExcelIDPK[i] = v_CellExcelIDOld[i].substring(0 ,1) + $ParserFormulaSplit + v_CellExcelIDOld[i].substring(1); } v_CellExcelIDNew[i] = calcCellOffset(v_CellExcelIDOld[i] ,i_OffsetRow ,i_OffsetCol); } v_Formula = StringHelp.replaceAll(v_Formula ,v_CellExcelIDOld ,v_CellExcelIDPK); v_Formula = StringHelp.replaceAll(v_Formula ,v_CellExcelIDPK ,v_CellExcelIDNew); return v_Formula; }
Example 4
Source File: ExcelFormula.java From hy.common.report with Apache License 2.0 | 5 votes |
/** * 解释公式,将公式中的单元格ID独立提取出来。 * * 1. 会去除重复的单元格ID * 2. 会去除绝对行、绝对列定位的单元格ID * 3. 保留只绝对行 或 只绝对列定位的单格ID,去除绝对行及绝对列的单元格ID * * @author ZhengWei(HY) * @createDate 2020-05-20 * @version v1.0 * * @param i_Formula Excle公式 * @return */ public static String [] parserFormula(String i_Formula) { if ( Help.isNull(i_Formula) ) { return new String[0]; } String v_CellIDs = ""; v_CellIDs = StringHelp.trim(i_Formula.trim().toUpperCase()); v_CellIDs = StringHelp.replaceAll(v_CellIDs ,$Formulas ,new String[] {$ParserFormulaSplit}); v_CellIDs = StringHelp.trimToDistinct(v_CellIDs ,$ParserFormulaSplit); String [] v_CellIDArr = v_CellIDs.split($ParserFormulaSplit); if ( Help.isNull(v_CellIDArr) ) { return new String[0]; } List<String> v_CellIDList = Help.toDistinct(v_CellIDArr); for (int i=v_CellIDList.size()-1; i>=0; i--) { if ( Help.isNull(v_CellIDList.get(i)) ) { // 去除空 v_CellIDList.remove(i); } else if ( StringHelp.getCount(v_CellIDList.get(i) ,"\\$") >= 2 ) { // 去除绝对行、绝对列定位的单元格ID v_CellIDList.remove(i); } } if ( Help.isNull(v_CellIDList) ) { return new String[0]; } return v_CellIDList.toArray(new String[] {}); }
Example 5
Source File: ExcelFormula.java From hy.common.report with Apache License 2.0 | 5 votes |
/** * 将Excel单元格ID,转换为Java语言标识的行号、列号。 * * 如,将A1翻译为,第1列第1行,实际返回 0,0 ,下标均从0开始 * * @author ZhengWei(HY) * @createDate 2020-05-19 * @version v1.0 * * @param i_CellExcelID Excel单元格ID,如1 * @return */ public static RCell cellIDtoJava(String i_CellExcelID) { if ( Help.isNull(i_CellExcelID) ) { return null; } String [] v_CEIDArr = i_CellExcelID.split("!"); String v_CEID = v_CEIDArr[v_CEIDArr.length - 1]; String v_CellExcelID = StringHelp.replaceAll(v_CEID.trim().toUpperCase() ,"$" ,""); String v_RowName = StringHelp.replaceAll(v_CellExcelID ,$A_TO_Z ,new String [] {""}); if ( Help.isNull(v_RowName) || !Help.isNumber(v_RowName) || StringHelp.isContains(v_RowName ,"." ,"-" ," ") ) { return null; } int v_RowNo = Integer.parseInt(v_RowName); String v_ColName = StringHelp.replaceAll(v_CellExcelID ,v_RowNo + "" ,""); if ( v_ColName.length() <= 0 || v_ColName.length() > 3 ) { return null; } RCell v_Ret = new RCell(); v_Ret.setRowNo( v_RowNo - 1); v_Ret.setColNo(StringHelp.reABC26(v_ColName)); v_Ret.setFixedRow(v_CEID.trim().indexOf("$") > 0); v_Ret.setFixedCol(v_CEID.trim().startsWith("$")); return v_Ret; }
Example 6
Source File: ExcelHelp.java From hy.common.report with Apache License 2.0 | 4 votes |
/** * 复制模板工作表的打印区域到数据工作表中 * 1. 精确定位复杂报表(标题不是在同一行或多行,而是标题与数据相互交融显示)的打印区域 * 2. 确保同一Excel在不同电脑上打印分页是一样(但不保证打印DPI,即行高是一样的) * * @author ZhengWei(HY) * @createDate 2020-05-11 * @version v1.0 * * @param i_FromSheet 源工作表 * @param i_ToSheet 目标工作表 * @param i_ToSheetLastRowNum 目标工作表原用的数据。下标从0开始,0表示目标工作表还未写入任何数据 * @param i_NewDataSize 本次数据(或追加数据)的大小,即分页页数 */ public final static void copyPrintSetup(Sheet i_FromSheet ,Sheet i_ToSheet ,int i_ToSheetLastRowNum ,int i_NewDataSize) { int v_FromSheetIndex = i_FromSheet.getWorkbook().getSheetIndex(i_FromSheet); int v_ToSheetIndex = i_ToSheet .getWorkbook().getSheetIndex(i_ToSheet); String v_FromSheetName = i_FromSheet.getWorkbook().getSheetName(v_FromSheetIndex); String v_ToSheetName = i_ToSheet .getWorkbook().getSheetName(v_ToSheetIndex); String v_FromPrintArea = i_FromSheet.getWorkbook().getPrintArea(v_FromSheetIndex); String v_ToPrintArea = i_ToSheet .getWorkbook().getPrintArea(v_ToSheetIndex); if ( Help.isNull(v_FromPrintArea) || i_NewDataSize <= 0 ) { return; } String [] v_RepalceSpace = {""}; StringBuilder v_ToPrintAreaBuffer = new StringBuilder(); v_FromPrintArea = StringHelp.replaceAll(v_FromPrintArea ,new String[] {v_FromSheetName + "!" ,"$"} ,v_RepalceSpace); if ( !Help.isNull(v_ToPrintArea) ) { v_ToPrintArea = StringHelp.replaceAll(v_ToPrintArea ,new String[] {v_ToSheetName + "!" ,"$"} ,v_RepalceSpace); v_ToPrintAreaBuffer.append(v_ToPrintArea).append(","); } String [] v_SEArr = v_FromPrintArea.split(":"); int v_StartRow = ExcelFormula.cellIDtoJava(v_SEArr[0]).getRowNo() + 1; int v_EndRow = ExcelFormula.cellIDtoJava(v_SEArr[1]).getRowNo() + 1; int v_PageRowSize = v_EndRow - v_StartRow + 1; String v_StartColumn = StringHelp.replaceAll(v_SEArr[0] ,v_StartRow + "" ,""); String v_EndColumn = StringHelp.replaceAll(v_SEArr[1] ,v_EndRow + "" ,""); v_StartRow += i_ToSheetLastRowNum; v_EndRow += i_ToSheetLastRowNum; for (int v_PageNo=1; v_PageNo<=i_NewDataSize; v_PageNo++) { v_ToPrintAreaBuffer.append(v_StartColumn).append(v_StartRow + v_PageRowSize * (v_PageNo - 1)); v_ToPrintAreaBuffer.append(":"); v_ToPrintAreaBuffer.append(v_EndColumn) .append(v_EndRow + v_PageRowSize * (v_PageNo - 1)); if ( v_PageNo < i_NewDataSize ) { v_ToPrintAreaBuffer.append(","); } } // 设置对应工作表的打印区域 i_ToSheet.getWorkbook().setPrintArea(v_ToSheetIndex ,v_ToPrintAreaBuffer.toString()); }
Example 7
Source File: ExcelHelp.java From hy.common.report with Apache License 2.0 | 4 votes |
/** * 通过分隔符设定的打印区域到数据工作表中 * 1. 精确定位复杂报表(标题不是在同一行或多行,而是标题与数据相互交融显示)的打印区域 * 2. 确保同一Excel在不同电脑上打印分页是一样(但不保证打印DPI,即行高是一样的) * * @author ZhengWei(HY) * @createDate 2020-05-11 * @version v1.0 * * @param i_FromSheet 源工作表 * @param i_ToSheet 目标工作表 * @param i_ToSheetLastRowNum 目标工作表原用的数据。下标从0开始,0表示目标工作表还未写入任何数据 * @param i_NewDataSize 本次数据(或追加数据)的大小,即分页页数 */ public final static void setPrintRowBreaks(Sheet i_FromSheet ,Sheet i_ToSheet ,int i_ToSheetLastRowNum ,int i_NewDataSize) { int v_FromSheetIndex = i_FromSheet.getWorkbook().getSheetIndex(i_FromSheet); int v_ToSheetIndex = i_ToSheet .getWorkbook().getSheetIndex(i_ToSheet); String v_FromSheetName = i_FromSheet.getWorkbook().getSheetName(v_FromSheetIndex); String v_ToSheetName = i_ToSheet .getWorkbook().getSheetName(v_ToSheetIndex); String v_FromPrintArea = i_FromSheet.getWorkbook().getPrintArea(v_FromSheetIndex); String v_ToPrintArea = i_ToSheet .getWorkbook().getPrintArea(v_ToSheetIndex); if ( Help.isNull(v_FromPrintArea) || i_NewDataSize <= 0 ) { return; } String [] v_RepalceSpace = {""}; v_FromPrintArea = StringHelp.replaceAll(v_FromPrintArea ,new String[] {v_FromSheetName + "!" ,"$"} ,v_RepalceSpace); if ( !Help.isNull(v_ToPrintArea) ) { v_ToPrintArea = StringHelp.replaceAll(v_ToPrintArea ,new String[] {v_ToSheetName + "!" ,"$"} ,v_RepalceSpace); } if ( i_ToSheetLastRowNum > 0 ) { i_ToSheet.setRowBreak(i_ToSheetLastRowNum); } String [] v_A_TO_Z = {"A" ,"B" ,"C" ,"D" ,"E" ,"F" ,"G" ,"H" ,"I" ,"J" ,"K" ,"L" ,"M" ,"N" ,"O" ,"P" ,"Q" ,"R" ,"S" ,"T" ,"U" ,"V" ,"W" ,"X" ,"Y" ,"Z"}; String [] v_SEArr = v_FromPrintArea.split(":"); int v_StartRow = Integer.parseInt(StringHelp.replaceAll(v_SEArr[0] ,v_A_TO_Z ,v_RepalceSpace)); int v_EndRow = Integer.parseInt(StringHelp.replaceAll(v_SEArr[1] ,v_A_TO_Z ,v_RepalceSpace)); int v_PageRowSize = v_EndRow - v_StartRow + 1; v_StartRow += i_ToSheetLastRowNum; v_EndRow += i_ToSheetLastRowNum; for (int v_PageNo=1; v_PageNo<=i_NewDataSize; v_PageNo++) { if ( v_PageNo == 1 && i_ToSheetLastRowNum > 0 ) { i_ToSheet.setRowBreak(v_StartRow + v_PageRowSize * (v_PageNo - 1) - 1); } if ( i_ToSheetLastRowNum > 0 ) { // 追加模式下,在前置已有数据的情况下,因 i_ToSheetLastRowNum 的下标是从0开始的,因此不在-1。 i_ToSheet.setRowBreak(v_EndRow + v_PageRowSize * (v_PageNo - 1)); } else { i_ToSheet.setRowBreak(v_EndRow + v_PageRowSize * (v_PageNo - 1) - 1); } } }