| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class CSVReader extends Reader { | |
| 6 | |
| 7 CSVReader() : super() { } | |
| 8 | |
| 9 void loadSpreadsheet(Spreadsheet spreadsheet, List<String> csv) { | |
| 10 Style defaultFormat = new Style(); | |
| 11 // Hardcode $1000.12 format for now | |
| 12 Style currencyFormat = defaultFormat.setNumericFormatByIndex(4); | |
| 13 // Use % format for the interest rate | |
| 14 Style percentageFormat = defaultFormat.setNumericFormatByIndex(8); | |
| 15 for (int row = 0; row < csv.length; row++) { | |
| 16 List<String> cells = StringUtils.split(csv[row], ",".charCodeAt(0)); | |
| 17 for (int col = 0; col < cells.length; col++) { | |
| 18 String formula = cells[col]; | |
| 19 RowCol rowCol = new RowCol(row + 1, col + 1); | |
| 20 CellLocation location = new CellLocation(spreadsheet, rowCol); | |
| 21 spreadsheet.execute(new SetCellContentsCommand(location, formula)); | |
| 22 if ((row == 1 && (col == 0 || col == 3)) || (row > 2 && col > 0)) { | |
| 23 spreadsheet.setCellStyle(location.rowCol, currencyFormat); | |
| 24 } else if (row == 2 && col == 2) { | |
| 25 spreadsheet.setCellStyle(location.rowCol, percentageFormat); | |
| 26 } else { | |
| 27 spreadsheet.setCellStyle(location.rowCol, defaultFormat); | |
| 28 } | |
| 29 } | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 List<String> makeExample(String id) { | |
| 34 int years = 30; | |
| 35 int payments = years * 12; | |
| 36 List<String> csv = new List<String>(payments + 4); | |
| 37 csv[0] = "\"Loan Amount\",\"Interest Rate\",\"Years\",\"Monthly Payment\""; | |
| 38 csv[1] = "375000,.05375,${years},\"=ROUND((R2C1*((R2C2/12)/(1-POWER((1+(R2C2
/12))," | |
| 39 + "(-12*R2C3))))),2)\""; | |
| 40 csv[2] = "\"Payment #\",\"Balance\",\"Interest\",\"Principal\""; | |
| 41 csv[3] = "1,\"=R2C1\",\"=(RC[-1]*R2C2)/12\",\"=R2C4-RC[-1]\""; | |
| 42 for (int i = 4; i < payments + 3; i++) { | |
| 43 csv[i] = "\"=R[-1]C+1\",\"=R[-1]C-R[-1]C[2]\",\"=(RC[-1]*R2C2)/12\",\"=R2C
4-RC[-1]\""; | |
| 44 } | |
| 45 csv[payments + 3] = "\"Totals\",\"=C364+D364\",\"=SUM(C4:C363)\",\"=SUM(D4:D
363)\""; | |
| 46 return csv; | |
| 47 } | |
| 48 } | |
| OLD | NEW |