View | Details | Raw Unified | Return to bug 41726
Collapse All | Expand All

(-)/Users/ce/Documents/workspace/POI/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java (-18 / +34 lines)
Lines 205-212 Link Here
205
            Ptg ptg = (Ptg) field_7_parsed_expr.get(k);
205
            Ptg ptg = (Ptg) field_7_parsed_expr.get(k);
206
            if (ptg instanceof RefNPtg) {
206
            if (ptg instanceof RefNPtg) {
207
              RefNPtg refNPtg = (RefNPtg)ptg;
207
              RefNPtg refNPtg = (RefNPtg)ptg;
208
              ptg = new ReferencePtg( (short)(formulaRow + refNPtg.getRow()),
208
              ptg = new ReferencePtg( (short)(fixupRelativeRow(formulaRow,refNPtg.getRow(),refNPtg.isRowRelative())),
209
                                      (byte)(formulaColumn + refNPtg.getColumn()),
209
                                      (byte)(fixupRelativeColumn(formulaColumn,refNPtg.getColumn(),refNPtg.isColRelative())),
210
                                     refNPtg.isRowRelative(),
210
                                     refNPtg.isRowRelative(),
211
                                     refNPtg.isColRelative());
211
                                     refNPtg.isColRelative());
212
            } else if (ptg instanceof RefNVPtg) {
212
            } else if (ptg instanceof RefNVPtg) {
Lines 211-218 Link Here
211
                                     refNPtg.isColRelative());
211
                                     refNPtg.isColRelative());
212
            } else if (ptg instanceof RefNVPtg) {
212
            } else if (ptg instanceof RefNVPtg) {
213
              RefNVPtg refNVPtg = (RefNVPtg)ptg;
213
              RefNVPtg refNVPtg = (RefNVPtg)ptg;
214
              ptg = new RefVPtg( (short)(formulaRow + refNVPtg.getRow()),
214
              ptg = new RefVPtg( (short)(fixupRelativeRow(formulaRow,refNVPtg.getRow(),refNVPtg.isRowRelative())),
215
                                 (byte)(formulaColumn + refNVPtg.getColumn()),
215
                                 (byte)(fixupRelativeColumn(formulaColumn,refNVPtg.getColumn(),refNVPtg.isColRelative())),
216
                                 refNVPtg.isRowRelative(),
216
                                 refNVPtg.isRowRelative(),
217
                                 refNVPtg.isColRelative());
217
                                 refNVPtg.isColRelative());
218
            } else if (ptg instanceof RefNAPtg) {
218
            } else if (ptg instanceof RefNAPtg) {
Lines 217-224 Link Here
217
                                 refNVPtg.isColRelative());
217
                                 refNVPtg.isColRelative());
218
            } else if (ptg instanceof RefNAPtg) {
218
            } else if (ptg instanceof RefNAPtg) {
219
              RefNAPtg refNAPtg = (RefNAPtg)ptg;
219
              RefNAPtg refNAPtg = (RefNAPtg)ptg;
220
              ptg = new RefAPtg( (short)(formulaRow + refNAPtg.getRow()),
220
              ptg = new RefAPtg( (short)(fixupRelativeRow(formulaRow,refNAPtg.getRow(),refNAPtg.isRowRelative())),
221
                                 (byte)(formulaColumn + refNAPtg.getColumn()),
221
                                 (byte)(fixupRelativeColumn(formulaColumn,refNAPtg.getColumn(),refNAPtg.isColRelative())),
222
                                 refNAPtg.isRowRelative(),
222
                                 refNAPtg.isRowRelative(),
223
                                 refNAPtg.isColRelative());
223
                                 refNAPtg.isColRelative());
224
            } else if (ptg instanceof AreaNPtg) {
224
            } else if (ptg instanceof AreaNPtg) {
Lines 223-232 Link Here
223
                                 refNAPtg.isColRelative());
223
                                 refNAPtg.isColRelative());
224
            } else if (ptg instanceof AreaNPtg) {
224
            } else if (ptg instanceof AreaNPtg) {
225
              AreaNPtg areaNPtg = (AreaNPtg)ptg;
225
              AreaNPtg areaNPtg = (AreaNPtg)ptg;
226
              ptg = new AreaPtg((short)(formulaRow + areaNPtg.getFirstRow()),
226
              ptg = new AreaPtg((short)(fixupRelativeRow(formulaRow,areaNPtg.getFirstRow(),areaNPtg.isFirstRowRelative())),
227
                                (short)(formulaRow + areaNPtg.getLastRow()),
227
                                (short)(fixupRelativeRow(formulaRow,areaNPtg.getLastRow(),areaNPtg.isLastRowRelative())),
228
                                (short)(formulaColumn + areaNPtg.getFirstColumn()),
228
                                (short)(fixupRelativeColumn(formulaColumn,areaNPtg.getFirstColumn(),areaNPtg.isFirstColRelative())),
229
                                (short)(formulaColumn + areaNPtg.getLastColumn()),
229
                                (short)(fixupRelativeColumn(formulaColumn,areaNPtg.getLastColumn(),areaNPtg.isLastColRelative())),
230
                                areaNPtg.isFirstRowRelative(),
230
                                areaNPtg.isFirstRowRelative(),
231
                                areaNPtg.isLastRowRelative(),
231
                                areaNPtg.isLastRowRelative(),
232
                                areaNPtg.isFirstColRelative(),
232
                                areaNPtg.isFirstColRelative(),
Lines 233-242 Link Here
233
                                areaNPtg.isLastColRelative());
233
                                areaNPtg.isLastColRelative());
234
            } else if (ptg instanceof AreaNVPtg) {
234
            } else if (ptg instanceof AreaNVPtg) {
235
              AreaNVPtg areaNVPtg = (AreaNVPtg)ptg;
235
              AreaNVPtg areaNVPtg = (AreaNVPtg)ptg;
236
              ptg = new AreaVPtg((short)(formulaRow + areaNVPtg.getFirstRow()),
236
              ptg = new AreaVPtg((short)(fixupRelativeRow(formulaRow,areaNVPtg.getFirstRow(),areaNVPtg.isFirstRowRelative())),
237
                                (short)(formulaRow + areaNVPtg.getLastRow()),
237
                                (short)(fixupRelativeRow(formulaRow,areaNVPtg.getLastRow(),areaNVPtg.isLastRowRelative())),
238
                                (short)(formulaColumn + areaNVPtg.getFirstColumn()),
238
                                (short)(fixupRelativeColumn(formulaColumn,areaNVPtg.getFirstColumn(),areaNVPtg.isFirstColRelative())),
239
                                (short)(formulaColumn + areaNVPtg.getLastColumn()),
239
                                (short)(fixupRelativeColumn(formulaColumn,areaNVPtg.getLastColumn(),areaNVPtg.isLastColRelative())),
240
                                areaNVPtg.isFirstRowRelative(),
240
                                areaNVPtg.isFirstRowRelative(),
241
                                areaNVPtg.isLastRowRelative(),
241
                                areaNVPtg.isLastRowRelative(),
242
                                areaNVPtg.isFirstColRelative(),
242
                                areaNVPtg.isFirstColRelative(),
Lines 243-252 Link Here
243
                                areaNVPtg.isLastColRelative());
243
                                areaNVPtg.isLastColRelative());
244
            } else if (ptg instanceof AreaNAPtg) {
244
            } else if (ptg instanceof AreaNAPtg) {
245
              AreaNAPtg areaNAPtg = (AreaNAPtg)ptg;
245
              AreaNAPtg areaNAPtg = (AreaNAPtg)ptg;
246
              ptg = new AreaAPtg((short)(formulaRow + areaNAPtg.getFirstRow()),
246
              ptg = new AreaAPtg((short)(fixupRelativeRow(formulaRow,areaNAPtg.getFirstRow(),areaNAPtg.isFirstRowRelative())),
247
                                (short)(formulaRow + areaNAPtg.getLastRow()),
247
                                (short)(fixupRelativeRow(formulaRow,areaNAPtg.getLastRow(),areaNAPtg.isLastRowRelative())),
248
                                (short)(formulaColumn + areaNAPtg.getFirstColumn()),
248
                                (short)(fixupRelativeColumn(formulaColumn,areaNAPtg.getFirstColumn(),areaNAPtg.isFirstColRelative())),
249
                                (short)(formulaColumn + areaNAPtg.getLastColumn()),
249
                                (short)(fixupRelativeColumn(formulaColumn,areaNAPtg.getLastColumn(),areaNAPtg.isLastColRelative())),
250
                                areaNAPtg.isFirstRowRelative(),
250
                                areaNAPtg.isFirstRowRelative(),
251
                                areaNAPtg.isLastRowRelative(),
251
                                areaNAPtg.isLastRowRelative(),
252
                                areaNAPtg.isFirstColRelative(),
252
                                areaNAPtg.isFirstColRelative(),
Lines 261-266 Link Here
261
        throw new RuntimeException("Shared Formula Conversion: Coding Error");
261
        throw new RuntimeException("Shared Formula Conversion: Coding Error");
262
      }
262
      }
263
    }
263
    }
264
    
265
    private short fixupRelativeColumn(int currentcolumn, short column, boolean relative) {
266
    	if(relative) {
267
    		if((column&128)!=0) column=(short)(column-256);
268
    		column+=currentcolumn;
269
    	}
270
    	return column;
271
	}
272
273
	private short fixupRelativeRow(int currentrow, short row, boolean relative) {
274
		if(relative) {
275
			if((row&32768)!=0) row=(short)(row-65536);
276
			row+=currentrow;
277
		}
278
		return row;
279
	}
264
280
265
	/**
281
	/**
266
	 * Mirroring formula records so it is registered in the ValueRecordsAggregate
282
	 * Mirroring formula records so it is registered in the ValueRecordsAggregate

Return to bug 41726