2016-03-04 03:56:28 +00:00
|
|
|
package com.bytezone.diskbrowser.visicalc;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-08 09:39:35 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TreeMap;
|
2015-06-01 09:35:51 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2016-02-24 21:11:14 +00:00
|
|
|
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
2016-08-01 01:22:34 +00:00
|
|
|
import com.bytezone.diskbrowser.visicalc.Value.ValueType;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-15 20:06:04 +00:00
|
|
|
public class Sheet
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-02-04 00:31:44 +00:00
|
|
|
private static final Pattern addressPattern =
|
2016-03-08 09:39:35 +00:00
|
|
|
Pattern.compile ("([AB]?[A-Z])([0-9]{1,3}):");
|
2016-03-15 20:27:47 +00:00
|
|
|
private static final byte END_OF_LINE_TOKEN = (byte) 0x8D;
|
2016-03-16 06:15:39 +00:00
|
|
|
private static final int FORMAT_LENGTH = 3;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-15 20:06:04 +00:00
|
|
|
private final Map<Integer, Cell> rowOrderCells = new TreeMap<Integer, Cell> ();
|
|
|
|
private final Map<Integer, Cell> columnOrderCells = new TreeMap<Integer, Cell> ();
|
2016-03-11 02:54:31 +00:00
|
|
|
private final List<String> lines = new ArrayList<String> ();
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-15 20:06:04 +00:00
|
|
|
private Cell currentCell = null;
|
|
|
|
private char defaultFormat;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-04 05:27:14 +00:00
|
|
|
private final Map<Integer, Integer> columnWidths = new TreeMap<Integer, Integer> ();
|
2016-03-08 09:39:35 +00:00
|
|
|
private int columnWidth = 12;
|
2016-03-15 20:27:47 +00:00
|
|
|
|
|
|
|
private char recalculation = 'A'; // auto/manual
|
2016-03-15 20:06:04 +00:00
|
|
|
private char recalculationOrder = 'C'; // row/column
|
2016-03-15 20:27:47 +00:00
|
|
|
|
|
|
|
private int highestColumn;
|
|
|
|
private int highestRow;
|
2016-03-04 05:27:14 +00:00
|
|
|
|
2015-06-01 09:35:51 +00:00
|
|
|
// Maximum cell = BK254
|
|
|
|
|
|
|
|
//Commands:
|
|
|
|
// /G<address> goto
|
|
|
|
// /B blank the cell
|
|
|
|
// /C clear and home
|
|
|
|
// A-Z label (" to force a label)
|
|
|
|
// 0-9.+-()*/@# value (+ to force a value)
|
|
|
|
|
|
|
|
// /S Storage (ISLDWR)
|
|
|
|
// /SI Storage init
|
|
|
|
// /SS Storage Save
|
|
|
|
// /SL Storage Load
|
|
|
|
// /SD Storage Delete
|
|
|
|
// /SW Storage Write (to cassette)
|
|
|
|
// /SR Storage Read (from cassette)
|
|
|
|
|
|
|
|
// /R Replicate
|
|
|
|
|
|
|
|
// /G Global (CORF)
|
|
|
|
// /GF Global Format (DGILR$*)
|
|
|
|
// /GFI Global Format Integer
|
|
|
|
// /GF$ Global Format Currency
|
|
|
|
// /GC Global Column <width>
|
|
|
|
// /GR Global
|
2016-03-08 09:39:35 +00:00
|
|
|
// /GRA Recalculation Auto
|
2015-06-01 09:35:51 +00:00
|
|
|
// /GO Global
|
2016-03-08 09:39:35 +00:00
|
|
|
// /GOC Calculation Order - Columns first
|
2015-06-01 09:35:51 +00:00
|
|
|
|
|
|
|
// /T Titles (HVBN)
|
|
|
|
// /TH fix Horizontal Titles
|
|
|
|
// /TV fix Vertical Titles
|
|
|
|
// /TB fix Both Titles
|
|
|
|
// /TN fix Neither
|
|
|
|
|
|
|
|
// /W Window (HV1SU)
|
|
|
|
// /WV Window Vertical (split on cursor column)
|
|
|
|
// /WH Window Horizontal (split on cursor row)
|
|
|
|
|
2016-02-04 00:31:44 +00:00
|
|
|
/*
|
|
|
|
from: Apple II TextFiles
|
|
|
|
http://www.textfiles.com/apple/
|
|
|
|
|
|
|
|
|
|
|
|
*----------------------*
|
|
|
|
VISICALC COMMAND CHART
|
|
|
|
BY: NIGHT HAWK
|
|
|
|
*----------------------*
|
|
|
|
|
|
|
|
/B SET AN ENTRY TO BLANK
|
|
|
|
|
|
|
|
/C CLEARS THE SHEET, SETTING ALL ENTRIES TO BLANK
|
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
/D DELETE
|
|
|
|
/DR THE ROW
|
|
|
|
/DC COLUMN ON WHICH THE CURSOR LIES
|
2016-02-04 00:31:44 +00:00
|
|
|
|
|
|
|
/E ALLOWS EDITING OF THE ENTRY CONTENTS OF ANY ENTRY POSITION
|
|
|
|
BY REDISPLAYING IT ON THE EDIT LINE. USE <- -> KEYS & ESC.
|
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
/F FORMATS:
|
2016-02-04 00:31:44 +00:00
|
|
|
/FG GENERAL
|
2016-03-14 08:58:54 +00:00
|
|
|
/FI INTEGER
|
|
|
|
/F$ DOLLAR AND CENTS
|
|
|
|
/FL LEFT JUSTIFIED
|
|
|
|
/FR RIGHT JUSTIFIED
|
|
|
|
/F* GRAPH
|
|
|
|
/FD DEFAULT
|
2016-02-04 00:31:44 +00:00
|
|
|
|
|
|
|
/G GLOBAL COMMANDS. THESE APPLY TO THE ENTIRE SHEET OR WINDOW.
|
|
|
|
/GC SETS COLUMN WIDTH
|
|
|
|
/GF SETS THE GLOBAL DEFAULT FORMAT
|
|
|
|
/GO SETS THE ORDER OF RECALCULATION TO BE DOWN THE
|
|
|
|
COLUMNS OR ACROSS THE ROWS
|
|
|
|
/GR SETS RECALCULATION TO BE AUTOMATIC(/GRA) OR MANUAL(/GRM).
|
|
|
|
|
|
|
|
/I INSERTS A ROW(/IR) OR A COLUMN(/IC)
|
|
|
|
/M MOVES AN ENTIRE ROW OR COLUMN TO A NEW POSITION.
|
|
|
|
/P PRINT COMMAND
|
|
|
|
/R REPLICATE COMMAND
|
2016-03-14 08:58:54 +00:00
|
|
|
|
|
|
|
/S STORAGE COMMANDS
|
2016-03-01 22:51:56 +00:00
|
|
|
/SS SAVE
|
|
|
|
/SL LOAD
|
|
|
|
/SD DELETES SPECIFIED FILE ON DISK
|
2016-02-04 00:31:44 +00:00
|
|
|
/SI INITIALIZE A DISK ON SPECIFIED DRIVE
|
|
|
|
/SQ QUITS VISICALC
|
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
/T
|
|
|
|
/TH SETS A HORIZONTAL TITLE AREA
|
|
|
|
/TV SETS A VERTICAL TITLE AREA
|
|
|
|
/TB SET BOTH A HORIZONTAL & VERTICAL TITLE AREA
|
|
|
|
/TN RESETS THE WINDOWS TO HAVE NO TITLE AREAS
|
|
|
|
|
2016-02-04 00:31:44 +00:00
|
|
|
/V DISPLAYS VISICALC'S VERSION NUMBER ON THE PROMPT LINE
|
|
|
|
/W WINDOW CONTROL
|
|
|
|
/WH HORIZONTAL WINDOW
|
|
|
|
/WV VERTICAL WINDOW
|
|
|
|
/W1 RETURNS SCREEN TO ONE WINDOW
|
|
|
|
/WS SYNCHRONIZED WINDOWS
|
|
|
|
/WU UNSYNCHRONIZED
|
|
|
|
|
|
|
|
/- REPEATING LABEL
|
|
|
|
*/
|
|
|
|
|
2016-03-06 08:05:32 +00:00
|
|
|
public Sheet (byte[] buffer)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-04 05:27:14 +00:00
|
|
|
int last = buffer.length;
|
2016-03-14 08:58:54 +00:00
|
|
|
while (buffer[--last] == 0) // ignore trailing zeroes
|
2016-03-04 05:27:14 +00:00
|
|
|
;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-04 05:27:14 +00:00
|
|
|
int ptr = 0;
|
2016-03-06 23:52:46 +00:00
|
|
|
while (ptr < last)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-06 23:52:46 +00:00
|
|
|
int length = getLineLength (buffer, ptr);
|
|
|
|
String line = HexFormatter.getString (buffer, ptr, length);
|
|
|
|
lines.add (line);
|
|
|
|
processLine (line);
|
|
|
|
ptr += length + 1; // +1 for end-of-line token
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
calculate (recalculationOrder);
|
|
|
|
|
2016-03-13 10:57:20 +00:00
|
|
|
if (false)
|
2016-03-14 08:58:54 +00:00
|
|
|
printDebug ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void calculate (char order)
|
|
|
|
{
|
2016-03-15 20:06:04 +00:00
|
|
|
Map<Integer, Cell> cells = order == 'R' ? rowOrderCells : columnOrderCells;
|
|
|
|
for (Cell cell : cells.values ())
|
2016-08-01 01:22:34 +00:00
|
|
|
if (cell.is (ValueType.VALUE))
|
2016-03-15 20:06:04 +00:00
|
|
|
cell.calculate ();
|
2016-03-04 05:27:14 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 23:52:46 +00:00
|
|
|
private int getLineLength (byte[] buffer, int offset)
|
2016-03-04 05:27:14 +00:00
|
|
|
{
|
2016-03-06 23:52:46 +00:00
|
|
|
int ptr = offset;
|
2016-03-15 20:27:47 +00:00
|
|
|
while (buffer[ptr] != END_OF_LINE_TOKEN) // end-of-line token
|
2016-03-04 05:27:14 +00:00
|
|
|
ptr++;
|
2016-03-06 23:52:46 +00:00
|
|
|
return ptr - offset;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 09:39:35 +00:00
|
|
|
private void processLine (String line)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-15 20:06:04 +00:00
|
|
|
assert !line.isEmpty ();
|
2016-03-19 05:31:30 +00:00
|
|
|
// System.out.println (line);
|
2016-03-06 04:41:15 +00:00
|
|
|
|
2016-03-08 09:39:35 +00:00
|
|
|
if (line.startsWith ("/"))
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
switch (line.charAt (1))
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
case 'W':
|
2016-03-14 22:55:17 +00:00
|
|
|
// System.out.printf ("Skipping [%s]%n", line);
|
2015-06-01 09:35:51 +00:00
|
|
|
break;
|
2016-03-08 09:39:35 +00:00
|
|
|
case 'G':
|
|
|
|
switch (line.charAt (2))
|
2016-02-04 00:31:44 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
case 'R':
|
|
|
|
recalculation = line.charAt (3);
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
recalculationOrder = line.charAt (3);
|
|
|
|
break;
|
|
|
|
case 'P':
|
2016-03-14 22:55:17 +00:00
|
|
|
// System.out.printf ("Skipping [%s]%n", line);
|
2016-03-08 09:39:35 +00:00
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
columnWidth = Integer.parseInt (line.substring (3));
|
|
|
|
break;
|
2016-03-14 20:54:47 +00:00
|
|
|
case 'F':
|
|
|
|
defaultFormat = line.charAt (3);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
System.out.printf ("Unknown global format [%s]%n", line);
|
|
|
|
break;
|
2016-02-04 00:31:44 +00:00
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
break;
|
2016-03-08 09:39:35 +00:00
|
|
|
case 'X':
|
2016-03-14 22:55:17 +00:00
|
|
|
// System.out.printf ("Skipping [%s]%n", line);
|
2016-03-06 04:41:15 +00:00
|
|
|
break;
|
2015-06-01 09:35:51 +00:00
|
|
|
default:
|
2016-03-08 09:39:35 +00:00
|
|
|
System.out.printf ("Skipping [%s]%n", line);
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
2016-03-08 09:39:35 +00:00
|
|
|
return;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
2016-03-08 09:39:35 +00:00
|
|
|
|
|
|
|
if (!line.startsWith (">")) // GOTO cell
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
System.out.printf ("Error [%s]%n", line);
|
|
|
|
return;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
2016-03-08 09:39:35 +00:00
|
|
|
|
|
|
|
currentCell = null;
|
|
|
|
|
|
|
|
Matcher m = addressPattern.matcher (line);
|
|
|
|
if (m.find ())
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
Address address = new Address (m.group (1), m.group (2));
|
2016-03-15 20:06:04 +00:00
|
|
|
currentCell = rowOrderCells.get (address.rowKey);
|
2016-03-08 09:39:35 +00:00
|
|
|
|
|
|
|
int pos = line.indexOf (':'); // end of cell address
|
|
|
|
line = line.substring (pos + 1); // remove address from line
|
|
|
|
|
|
|
|
if (currentCell == null)
|
|
|
|
{
|
|
|
|
currentCell = new Cell (this, address);
|
|
|
|
if (!line.startsWith ("/G"))
|
2016-03-15 20:27:47 +00:00
|
|
|
addCell (currentCell);
|
2016-03-08 09:39:35 +00:00
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
2016-03-08 09:39:35 +00:00
|
|
|
else
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
System.out.printf ("Invalid cell address: %s%n", line);
|
|
|
|
return;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
2016-03-08 09:39:35 +00:00
|
|
|
|
|
|
|
assert currentCell != null;
|
|
|
|
|
2016-03-14 20:54:47 +00:00
|
|
|
if (line.startsWith ("/G")) // global column widths
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-08 09:39:35 +00:00
|
|
|
if (line.charAt (2) == 'C' && line.charAt (3) == 'C')
|
|
|
|
{
|
|
|
|
int width = Integer.parseInt (line.substring (4));
|
|
|
|
columnWidths.put (currentCell.address.column, width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
System.out.printf ("Unknown Global:[%s]%n", line);
|
|
|
|
|
|
|
|
return;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
2016-03-08 09:39:35 +00:00
|
|
|
|
2016-03-12 00:48:45 +00:00
|
|
|
// check for formatting commands
|
|
|
|
String format = "";
|
|
|
|
while (line.startsWith ("/"))
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-16 06:15:39 +00:00
|
|
|
String fmt = line.substring (0, FORMAT_LENGTH);
|
|
|
|
line = line.substring (FORMAT_LENGTH);
|
2016-03-14 20:54:47 +00:00
|
|
|
|
|
|
|
if (fmt.equals ("/TH") || fmt.equals ("/TV")) // lock titles ??
|
|
|
|
{
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
else
|
|
|
|
currentCell.format (fmt); // formatting command
|
|
|
|
|
2016-03-12 00:48:45 +00:00
|
|
|
format += fmt;
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 09:39:35 +00:00
|
|
|
if (!line.isEmpty ())
|
2016-03-14 20:54:47 +00:00
|
|
|
currentCell.setValue (line); // expression
|
2016-03-12 00:48:45 +00:00
|
|
|
|
2016-03-13 10:57:20 +00:00
|
|
|
if (false)
|
2016-03-12 00:48:45 +00:00
|
|
|
System.out.printf ("[%s][%-3s][%s]%n", currentCell.address, format, line);
|
2016-03-11 21:56:02 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 20:27:47 +00:00
|
|
|
private void addCell (Cell cell)
|
|
|
|
{
|
|
|
|
rowOrderCells.put (cell.address.rowKey, cell);
|
|
|
|
columnOrderCells.put (cell.address.columnKey, cell);
|
|
|
|
|
|
|
|
if (cell.address.row > highestRow)
|
|
|
|
highestRow = cell.address.row;
|
|
|
|
if (cell.address.column > highestColumn)
|
|
|
|
highestColumn = cell.address.column;
|
|
|
|
}
|
|
|
|
|
2016-03-11 21:56:02 +00:00
|
|
|
Cell getCell (String addressText)
|
|
|
|
{
|
2016-03-14 08:58:54 +00:00
|
|
|
return getCell (new Address (addressText));
|
2016-03-08 09:39:35 +00:00
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-07 04:37:01 +00:00
|
|
|
Cell getCell (Address address)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-15 20:06:04 +00:00
|
|
|
return rowOrderCells.get (address.rowKey);
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int size ()
|
|
|
|
{
|
2016-03-15 20:06:04 +00:00
|
|
|
return rowOrderCells.size ();
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 02:54:31 +00:00
|
|
|
public String getLines ()
|
|
|
|
{
|
|
|
|
StringBuilder text = new StringBuilder ();
|
|
|
|
|
|
|
|
for (String line : lines)
|
|
|
|
{
|
|
|
|
text.append (line);
|
|
|
|
text.append ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.length () > 0)
|
|
|
|
text.deleteCharAt (text.length () - 1);
|
|
|
|
|
|
|
|
return text.toString ();
|
|
|
|
}
|
|
|
|
|
2016-03-14 22:35:22 +00:00
|
|
|
public String getTextDisplay (boolean debug)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
|
|
|
StringBuilder text = new StringBuilder ();
|
2016-03-06 04:41:15 +00:00
|
|
|
String longLine;
|
|
|
|
if (false)
|
|
|
|
longLine = "%+++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
|
|
|
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
|
|
|
|
else
|
|
|
|
longLine = " "
|
|
|
|
+ " ";
|
2016-03-11 01:52:22 +00:00
|
|
|
String underline = "---------------------------------------------------------"
|
|
|
|
+ "-----------------------------------------------------------------";
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-14 22:55:17 +00:00
|
|
|
int lastRow = 0;
|
2016-03-05 21:53:29 +00:00
|
|
|
int lastColumn = 0;
|
2015-06-01 09:35:51 +00:00
|
|
|
|
2016-03-09 10:38:53 +00:00
|
|
|
StringBuilder heading = new StringBuilder (" ");
|
2016-03-15 20:27:47 +00:00
|
|
|
for (int column = 0; column <= highestColumn; column++)
|
2016-03-09 10:38:53 +00:00
|
|
|
{
|
|
|
|
int width = columnWidth;
|
2016-03-15 20:27:47 +00:00
|
|
|
if (columnWidths.containsKey (column))
|
|
|
|
width = columnWidths.get (column);
|
|
|
|
|
|
|
|
char letter1 = column < 26 ? ' ' : column < 52 ? 'A' : 'B';
|
|
|
|
char letter2 = (char) ((column % 26) + 'A');
|
2016-03-09 10:38:53 +00:00
|
|
|
|
2016-03-14 08:58:54 +00:00
|
|
|
String fmt =
|
|
|
|
String.format ("%s%s%%%d.%ds", letter1, letter2, (width - 2), (width - 2));
|
2016-03-09 10:38:53 +00:00
|
|
|
if (width == 1)
|
2016-03-14 08:58:54 +00:00
|
|
|
heading.append (letter2);
|
2016-03-10 02:39:23 +00:00
|
|
|
else if (width == 2)
|
2016-03-14 08:58:54 +00:00
|
|
|
heading.append (String.format ("%s%s", letter1, letter2));
|
2016-03-09 10:38:53 +00:00
|
|
|
else
|
2016-03-11 01:52:22 +00:00
|
|
|
heading.append (String.format (fmt, underline));
|
2016-03-09 10:38:53 +00:00
|
|
|
}
|
2016-03-14 22:35:22 +00:00
|
|
|
|
|
|
|
if (debug)
|
2016-03-14 22:55:17 +00:00
|
|
|
{
|
2016-03-14 22:35:22 +00:00
|
|
|
text.append (heading);
|
2016-03-14 22:55:17 +00:00
|
|
|
text.append ("\n001:");
|
|
|
|
}
|
2016-03-09 10:38:53 +00:00
|
|
|
|
2016-03-15 20:06:04 +00:00
|
|
|
for (Cell cell : rowOrderCells.values ())
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-03-15 20:27:47 +00:00
|
|
|
Address cellAddress = cell.address;
|
|
|
|
while (lastRow < cellAddress.row)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
|
|
|
++lastRow;
|
2016-03-05 21:53:29 +00:00
|
|
|
lastColumn = 0;
|
2016-03-14 22:35:22 +00:00
|
|
|
if (debug)
|
|
|
|
text.append (String.format ("%n%03d:", lastRow + 1));
|
|
|
|
else
|
|
|
|
text.append ("\n");
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-15 20:27:47 +00:00
|
|
|
while (lastColumn < cellAddress.column)
|
2015-06-01 09:35:51 +00:00
|
|
|
{
|
2016-02-04 00:31:44 +00:00
|
|
|
int width = columnWidth;
|
2016-03-05 21:53:29 +00:00
|
|
|
if (columnWidths.containsKey (lastColumn))
|
|
|
|
width = columnWidths.get (lastColumn);
|
2016-02-04 00:31:44 +00:00
|
|
|
text.append (longLine.substring (0, width));
|
2015-06-01 09:35:51 +00:00
|
|
|
++lastColumn;
|
|
|
|
}
|
|
|
|
|
2016-03-11 22:32:19 +00:00
|
|
|
++lastColumn;
|
|
|
|
|
2016-02-04 00:31:44 +00:00
|
|
|
int colWidth = columnWidth;
|
2016-03-15 20:27:47 +00:00
|
|
|
if (columnWidths.containsKey (cellAddress.column))
|
|
|
|
colWidth = columnWidths.get (cellAddress.column);
|
2016-03-05 21:53:29 +00:00
|
|
|
|
2016-03-11 22:32:19 +00:00
|
|
|
text.append (cell.getText (colWidth, defaultFormat));
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|
|
|
|
return text.toString ();
|
|
|
|
}
|
2016-03-14 08:58:54 +00:00
|
|
|
|
|
|
|
private void printDebug ()
|
|
|
|
{
|
|
|
|
System.out.println ();
|
|
|
|
System.out.println ("Lines:");
|
|
|
|
for (String line : lines)
|
|
|
|
System.out.println (line);
|
|
|
|
|
|
|
|
System.out.println ();
|
|
|
|
System.out.println ("Cells:");
|
2016-03-15 20:06:04 +00:00
|
|
|
for (Cell cell : rowOrderCells.values ())
|
2016-03-14 08:58:54 +00:00
|
|
|
System.out.println (cell);
|
|
|
|
|
|
|
|
System.out.println ();
|
|
|
|
System.out.println ("Column widths:");
|
|
|
|
System.out.printf ("Default width : %3d%n", columnWidth);
|
|
|
|
for (Map.Entry<Integer, Integer> entry : columnWidths.entrySet ())
|
|
|
|
System.out.printf (" column %3d: %3d%n", entry.getKey (), entry.getValue ());
|
|
|
|
}
|
2015-06-01 09:35:51 +00:00
|
|
|
}
|