获取字符串大小

时间:2018-03-29 16:07:13

标签: string flutter

我想知道是否有一些函数返回类似于iOS中size of NSString的字符串大小?

实施例。我们需要在屏幕底部有一些Widget,首先我们应该只看到文本但是在用户拉出那个小部件后,我们会看到更多(类似于底页)。小部件的起始高度取决于字符串。

1 个答案:

答案 0 :(得分:1)

查看import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ReadWriteExcel { static Map<Integer, String> header = new LinkedHashMap<Integer, String>(); public List<LinkedHashMap<String, Object>> readExcel(String excelNameWithPath) { List<LinkedHashMap<String, Object>> tempList; XSSFWorkbook wb; int checkRow = 0; tempList = new ArrayList<LinkedHashMap<String, Object>>(); try { wb = new XSSFWorkbook(excelNameWithPath); // Iterate excel data row and cell wise for storing purpose in map. for (Row row : wb.getSheetAt(0)) { // If checkRow is 0, storing data into static variable // header.(as first row is header in every excel file.) if (checkRow == 0) { int indexMap = 0; for (Cell cell : row) { header.put(indexMap, cell.getRichStringCellValue().getString()); indexMap++; } checkRow++; continue; } Map<String, Object> tempMap = new LinkedHashMap<String, Object>(); for (Cell cell : row) { if (header.get(cell.getColumnIndex()) != null) { // System.out.println("cell.getCellTypeEnum() -->"+cell.getCellTypeEnum()); switch (cell.getCellTypeEnum()) { case STRING: tempMap.put(header.get(cell.getColumnIndex()), cell.getRichStringCellValue().getString()); // System.out.println("header.get(cell.getColumnIndex()) -->"+header.get(cell.getColumnIndex())); break; case NUMERIC: if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) tempMap.put(header.get(cell.getColumnIndex()), cell.getDateCellValue()); else tempMap.put(header.get(cell.getColumnIndex()), (int) cell.getNumericCellValue()); // System.out.println("header.get(cell.getColumnIndex()) -->"+header.get(cell.getColumnIndex())); break; case FORMULA: tempMap.put(header.get(cell.getColumnIndex()), cell.getCellFormula()); break; default: break; } } } tempList.add((LinkedHashMap<String, Object>) tempMap); } } catch (EncryptedDocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //System.out.println("Temp List data -->"+tempList); return tempList; } public XSSFWorkbook writeExcel(List<LinkedHashMap<String, Object>> myMap) { int rowNum = 0; int cellNum = 0; System.out.println("Entered into WriteExcel"); // Get workbook and sheet for processing. XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Output"); // Add header in newly created file. Row rowHeader = sheet.createRow(rowNum++); for (Integer Key : header.keySet()) { Cell cell = rowHeader.createCell(cellNum++); cell.setCellValue((String) (header.get(Key))); } // Iterate list one by one and get data saved in map. Calculate writing // factor based on settle position. // Writing factor = Settle Position / 1000. for (Map<String, Object> m : myMap) { Set<String> keyset = m.keySet(); for (String key : keyset) { if (key.equals("SETTLE POSITIONS")) { int settleNum = (Integer) m.get(key); settleNum = settleNum / 1000; for (int i = 0; i < settleNum; i++) { Row row = sheet.createRow(rowNum++); cellNum = 0; for (String key1 : keyset) { Cell cell = row.createCell(cellNum++); if (m.get(key1) instanceof Date) { cell.setCellValue((Date) (m.get(key1))); } else if (m.get(key1) instanceof String) { cell.setCellValue((String) (m.get(key1))); } else if (m.get(key1) instanceof Integer) { cell.setCellValue((Integer) (m.get(key1))); } else if (m.get(key1) instanceof Boolean) { cell.setCellValue((Boolean) (m.get(key1))); } } } } } } return workbook; } public long totalPositions(List<LinkedHashMap<String, Object>> excelDataList) { long totalPositions = 0L; for (Map<String, Object> m : excelDataList) { Set<String> keyset = m.keySet(); for (String key : keyset) { if (key.equals("SETTLE POSITIONS")) { int settleNum = (Integer) m.get(key); totalPositions+=settleNum; } } } System.out.println("Total Position : "+totalPositions); return totalPositions; } public void exportSelectedAccounts(Map<Integer, Integer> selectedAccounts, XSSFWorkbook tmpWorkbook) { XSSFWorkbook workbook = tmpWorkbook; XSSFSheet sheet = workbook.getSheetAt(0); XSSFWorkbook newWorkbook = new XSSFWorkbook(); XSSFSheet newSheet = newWorkbook.createSheet("Final"); XSSFRow srcRow, destRow; for (int i=1; i<=selectedAccounts.size(); i++){ for(Integer record : selectedAccounts.values()){ // System.out.println("Selected Row for Lottery :"+ record); srcRow= sheet.getRow(record); // System.out.println("Accounts Selected for lottery : "+ srcRow); destRow= newSheet.createRow(i); } } } } 它允许孩子先被放置然后你可以根据它的大小定位