public void Constructor() { WritableImage image = new WritableImage(gisImagePath); OutputRaster <Erdas74Pixel8> raster = new OutputRaster <Erdas74Pixel8>(image); raster.Close(); }
public void Dimensions() { WritableImage image = new WritableImage(gisImagePath); OutputRaster <Erdas74Pixel8> raster = new OutputRaster <Erdas74Pixel8>(image); Assert.AreEqual(60, raster.Dimensions.Rows); Assert.AreEqual(40, raster.Dimensions.Columns); raster.Close(); }
public void Metadata() { WritableImage image = new WritableImage(gisImagePath); OutputRaster <Erdas74Pixel8> raster = new OutputRaster <Erdas74Pixel8>(image); double data = 0.0; Assert.AreEqual(false, raster.Metadata.TryGetValue <double>("Anything", ref data)); raster.Close(); }
public void WritePixels() { WritableImage image = new WritableImage(gisImagePath); OutputRaster <Erdas74Pixel8> raster = new OutputRaster <Erdas74Pixel8>(image); Erdas74Pixel8 pixel8 = new Erdas74Pixel8(); int totPixels = raster.Dimensions.Rows * raster.Dimensions.Columns; for (int i = 0; i < totPixels; i++) { raster.WritePixel(pixel8); } raster.Close(); }
private void TryCtor <T>(string imagePath) where T : IPixel, new() { WritableImage image = null; try { image = new WritableImage(imagePath); OutputRaster <T> raster = new OutputRaster <T>(image); } catch (System.Exception exc) { Data.Output.WriteLine(exc.Message); throw; } finally { if (image != null) { image.Close(); } } }
public void Init() { gisImagePath = Data.MakeOutputPath("OutputRasterTests.gis"); WritableImage image; image = new WritableImage(gisImagePath, new Dimensions(60, 40), 1, System.TypeCode.Byte, null); image.Close(); lanImagePath = Data.MakeOutputPath("OutputRasterTests.lan"); image = new WritableImage(lanImagePath, new Dimensions(100, 50), 2, System.TypeCode.UInt16, null); image.Close(); }
public void WriteTooManyPixels() { try { WritableImage image = new WritableImage(gisImagePath); OutputRaster <Erdas74Pixel8> raster = new OutputRaster <Erdas74Pixel8>(image); using (raster) { Erdas74Pixel8 pixel8 = new Erdas74Pixel8(); int totPixels = raster.Dimensions.Rows * raster.Dimensions.Columns; for (int i = 0; i < totPixels; i++) { raster.WritePixel(pixel8); } // write one too many raster.WritePixel(pixel8); } } catch (System.Exception exc) { Data.Output.WriteLine(exc.Message); throw; } }
public void WriteTooManyPixels() { WritableImage image = null; try { Erdas74Pixel8 pixel = new Erdas74Pixel8(); image = new WritableImage(outputGisImagePath, new Dimensions(10, 10), 1, System.TypeCode.Byte, null); byte[] bytes = new byte[1]; bytes[0] = 1; pixel[0].SetBytes(bytes, 0); int pixCount = image.Dimensions.Rows * image.Dimensions.Columns; for (int i = 0; i < pixCount; i++) { image.WritePixel(pixel); } // one too many image.WritePixel(pixel); } catch (System.Exception exc) { Data.Output.WriteLine(exc.Message); throw; } finally { if (image != null) { image.Close(); } } }
public void WritePixels() { Erdas74Pixel8 pixel = new Erdas74Pixel8(); WritableImage image = new WritableImage(outputGisImagePath, new Dimensions(10, 10), 1, System.TypeCode.Byte, null); byte[] bytes = new byte[1]; bytes[0] = 1; pixel[0].SetBytes(bytes, 0); int pixCount = image.Dimensions.Rows * image.Dimensions.Columns; for (int i = 0; i < pixCount; i++) { image.WritePixel(pixel); } image.Close(); }
/** * If the inputFile was the test spreadsheet, then it modifies certain fields * of the writable copy * * @param w */ private void modify(WritableWorkbook w) { Console.WriteLine("Modifying..."); WritableSheet sheet = w.getSheet("modified"); WritableCell cell = null; CellFormat cf = null; Label l = null; WritableCellFeatures wcf = null; // Change the format of cell B4 to be emboldened cell = sheet.getWritableCell(1, 3); WritableFont bold = new WritableFont(WritableFont.ARIAL, WritableFont.DEFAULT_POINT_SIZE, WritableFont.BOLD); cf = new WritableCellFormat(bold); cell.setCellFormat(cf); // Change the format of cell B5 to be underlined cell = sheet.getWritableCell(1, 4); WritableFont underline = new WritableFont(WritableFont.ARIAL, WritableFont.DEFAULT_POINT_SIZE, WritableFont.NO_BOLD, false, UnderlineStyle.SINGLE); cf = new WritableCellFormat(underline); cell.setCellFormat(cf); // Change the point size of cell B6 to be 10 point cell = sheet.getWritableCell(1, 5); WritableFont tenpoint = new WritableFont(WritableFont.ARIAL, 10); cf = new WritableCellFormat(tenpoint); cell.setCellFormat(cf); // Change the contents of cell B7 to read "Label - mod" cell = sheet.getWritableCell(1, 6); if (cell.getType() == CellType.LABEL) { Label lc = (Label)cell; lc.setString(lc.getString() + " - mod"); } // Change cell B10 to display 7 dps cell = sheet.getWritableCell(1, 9); NumberFormat sevendps = new NumberFormat("#.0000000"); cf = new WritableCellFormat(sevendps); cell.setCellFormat(cf); // Change cell B11 to display in the format 1e4 cell = sheet.getWritableCell(1, 10); NumberFormat exp4 = new NumberFormat("0.####E0"); cf = new WritableCellFormat(exp4); cell.setCellFormat(cf); // Change cell B12 to be normal display cell = sheet.getWritableCell(1, 11); cell.setCellFormat(WritableWorkbook.NORMAL_STYLE); // Change the contents of cell B13 to 42 cell = sheet.getWritableCell(1, 12); if (cell.getType() == CellType.NUMBER) { Number n2 = (Number)cell; n2.setValue(42); } // Add 0.1 to the contents of cell B14 cell = sheet.getWritableCell(1, 13); if (cell.getType() == CellType.NUMBER) { Number n3 = (Number)cell; n3.setValue(n3.getValue() + 0.1); } // Change the date format of cell B17 to be a custom format cell = sheet.getWritableCell(1, 16); DateFormat df = new DateFormat("dd MMM yyyy HH:mm:ss"); cf = new WritableCellFormat(df); cell.setCellFormat(cf); // Change the date format of cell B18 to be a standard format cell = sheet.getWritableCell(1, 17); cf = new WritableCellFormat(DateFormats.FORMAT9); cell.setCellFormat(cf); // Change the date in cell B19 to be 18 Feb 1998, 11:23:28 cell = sheet.getWritableCell(1, 18); if (cell.getType() == CellType.DATE) { // TODO: fix this.... //DateTime dt = (DateTime)cell; //Calendar cal = Calendar.getInstance(); //cal.set(1998, 1, 18, 11, 23, 28); //Date d = cal.getTime(); //dt.setDate(d); } // Change the value in B23 to be 6.8. This should recalculate the // formula cell = sheet.getWritableCell(1, 22); if (cell.getType() == CellType.NUMBER) { Number n1 = (Number)cell; n1.setValue(6.8); } // Change the label in B30. This will have the effect of making // the original string unreferenced cell = sheet.getWritableCell(1, 29); if (cell.getType() == CellType.LABEL) { l = (Label)cell; l.setString("Modified string contents"); } // Insert a new row (number 35) sheet.insertRow(34); // Delete row 38 (39 after row has been inserted) sheet.removeRow(38); // Insert a new column (J) sheet.insertColumn(9); // Remove a column (L - M after column has been inserted) sheet.removeColumn(11); // Remove row 44 (contains a hyperlink), and then insert an empty // row just to keep the numbers consistent sheet.removeRow(43); sheet.insertRow(43); // Modify the hyperlinks WritableHyperlink[] hyperlinks = sheet.getWritableHyperlinks(); for (int i = 0; i < hyperlinks.Length; i++) { WritableHyperlink wh = hyperlinks[i]; if (wh.getColumn() == 1 && wh.getRow() == 39) { try { // Change the hyperlink that begins in cell B40 to be a different API wh.setURL(new Uri("http://www.andykhan.com/jexcelapi/index.html")); } catch (Exception e) { Console.WriteLine(e); } } else if (wh.getColumn() == 1 && wh.getRow() == 40) { wh.setFile(new FileInfo("../jexcelapi/docs/overview-summary.html")); } else if (wh.getColumn() == 1 && wh.getRow() == 41) { wh.setFile(new FileInfo("d:/home/jexcelapi/docs/jxl/package-summary.html")); } else if (wh.getColumn() == 1 && wh.getRow() == 44) { // Remove the hyperlink at B45 sheet.removeHyperlink(wh); } } // Change the background of cell F31 from blue to red WritableCell c = sheet.getWritableCell(5, 30); WritableCellFormat newFormat = new WritableCellFormat(c.getCellFormat()); newFormat.setBackground(Colour.RED); c.setCellFormat(newFormat); // Modify the contents of the merged cell l = new Label(0, 49, "Modified merged cells"); sheet.addCell(l); // Modify the chart data Number n = (Number)sheet.getWritableCell(0, 70); n.setValue(9); n = (Number)sheet.getWritableCell(0, 71); n.setValue(10); n = (Number)sheet.getWritableCell(0, 73); n.setValue(4); // Add in a cross sheet formula Formula f = new Formula(1, 80, "ROUND(COS(original!B10),2)"); sheet.addCell(f); // Add in a formula from the named cells f = new Formula(1, 83, "value1+value2"); sheet.addCell(f); // Add in a function formula using named cells f = new Formula(1, 84, "AVERAGE(value1,value1*4,value2)"); sheet.addCell(f); // Copy sheet 1 to sheet 3 // w.copySheet(0, "copy", 2); // Use the cell deep copy feature Label label = new Label(0, 88, "Some copied cells", cf); sheet.addCell(label); label = new Label(0, 89, "Number from B9"); sheet.addCell(label); WritableCell wc = sheet.getWritableCell(1, 9).copyTo(1, 89); sheet.addCell(wc); label = new Label(0, 90, "Label from B4 (modified format)"); sheet.addCell(label); wc = sheet.getWritableCell(1, 3).copyTo(1, 90); sheet.addCell(wc); label = new Label(0, 91, "Date from B17"); sheet.addCell(label); wc = sheet.getWritableCell(1, 16).copyTo(1, 91); sheet.addCell(wc); label = new Label(0, 92, "Boolean from E16"); sheet.addCell(label); wc = sheet.getWritableCell(4, 15).copyTo(1, 92); sheet.addCell(wc); label = new Label(0, 93, "URL from B40"); sheet.addCell(label); wc = sheet.getWritableCell(1, 39).copyTo(1, 93); sheet.addCell(wc); // Add some numbers for the formula copy for (int i = 0; i < 6; i++) { Number number = new Number(1, 94 + i, i + 1 + i / 8.0); sheet.addCell(number); } label = new Label(0, 100, "Formula from B27"); sheet.addCell(label); wc = sheet.getWritableCell(1, 26).copyTo(1, 100); sheet.addCell(wc); label = new Label(0, 101, "A brand new formula"); sheet.addCell(label); Formula formula = new Formula(1, 101, "SUM(B94:B96)"); sheet.addCell(formula); label = new Label(0, 102, "A copy of it"); sheet.addCell(label); wc = sheet.getWritableCell(1, 101).copyTo(1, 102); sheet.addCell(wc); // Remove the second image from the sheet WritableImage wi = sheet.getImage(1); sheet.removeImage(wi); wi = new WritableImage(1, 116, 2, 9, new FileInfo("resources/littlemoretonhall.png")); sheet.addImage(wi); // Add a list data validations label = new Label(0, 151, "Added drop down validation"); sheet.addCell(label); Blank b = new Blank(1, 151); wcf = new WritableCellFeatures(); ArrayList al = new ArrayList(); al.Add("The Fellowship of the Ring"); al.Add("The Two Towers"); al.Add("The Return of the King"); wcf.setDataValidationList(al); b.setCellFeatures(wcf); sheet.addCell(b); // Add a number data validation label = new Label(0, 152, "Added number validation 2.718 < x < 3.142"); sheet.addCell(label); b = new Blank(1, 152); wcf = new WritableCellFeatures(); wcf.setNumberValidation(2.718, 3.142, WritableCellFeatures.BETWEEN); b.setCellFeatures(wcf); sheet.addCell(b); // Modify the text in the first cell with a comment cell = sheet.getWritableCell(0, 156); l = (Label)cell; l.setString("Label text modified"); cell = sheet.getWritableCell(0, 157); wcf = cell.getWritableCellFeatures(); wcf.setComment("modified comment text"); cell = sheet.getWritableCell(0, 158); wcf = cell.getWritableCellFeatures(); wcf.removeComment(); // Modify the validation contents of the row 173 cell = sheet.getWritableCell(0, 172); wcf = cell.getWritableCellFeatures(); Range r = wcf.getSharedDataValidationRange(); Cell botright = r.getBottomRight(); sheet.removeSharedDataValidation(cell); al = new ArrayList(); al.Add("Stanley Featherstonehaugh Ukridge"); al.Add("Major Plank"); al.Add("Earl of Ickenham"); al.Add("Sir Gregory Parsloe-Parsloe"); al.Add("Honoria Glossop"); al.Add("Stiffy Byng"); al.Add("Bingo Little"); wcf.setDataValidationList(al); cell.setCellFeatures(wcf); sheet.applySharedDataValidation(cell, botright.getColumn() - cell.getColumn(), 1); //botright.getRow() - cell.getRow()); }
private void RecurseRender(Element elmt, decimal top, decimal left, bool renderAll) { top += elmt.Top; left += elmt.Left; if (!renderAll) { if (elmt is Container && !((Container)elmt).IsVisible) { return; } } if (elmt is TextElement) { TextElement te = elmt as TextElement; TextStyle ts = null; if (te.Style is TextStyle) { ts = (TextStyle)te.Style; } Int32 row = _rows.FindIndex(delegate(decimal d) { return(d == top); }); Int32 col; if (ts != null && ts.TextAlign == Rdl.Engine.Style.TextAlignEnum.Right) { col = _cols.FindIndex(delegate(decimal d) { return(d == left + elmt.Width); }) - 1; } else { col = _cols.FindIndex(delegate(decimal d) { return(d == left); }); } WritableCell cell; double dValue; if (double.TryParse(te.Text, out dValue)) { cell = new Number(col, row, dValue); } else { cell = new Label(col, row, te.Text); } cell.setCellFormat(formats[te.StyleIndex]); _ws.addCell(cell); } if (elmt is ImageElement) { ImageElement ie = elmt as ImageElement; Int32 row = _rows.FindIndex(delegate(decimal d) { return(d == top); }); Int32 col; if (ie != null) { col = _cols.FindIndex(delegate(decimal d) { return(d == left); }); } Rdl.Render.ImageData id = _report.ImageList[ie._imageIndex]; WritableImage img = new WritableImage(0, 0, (double)ie.Width, (double)ie.Height, id.GetImageData()); _ws.addImage(img); } if (elmt is Container) { foreach (Element child in ((Container)elmt).Children) { RecurseRender(child, top, left, renderAll); } } }
/** * Imports a sheet from a different workbook, doing a deep copy */ public void importSheet() { xfRecords = new Dictionary<int,WritableCellFormat>(); fonts = new Dictionary<int,int>(); formats = new Dictionary<int,int>(); deepCopyCells(); // Copy the column info records CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord[] readCirs = fromSheet.getColumnInfos(); for (int i = 0; i < readCirs.Length; i++) { CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord rcir = readCirs[i]; for (int j = rcir.getStartColumn(); j <= rcir.getEndColumn(); j++) { ColumnInfoRecord cir = new ColumnInfoRecord(rcir, j); int xfIndex = cir.getXfIndex(); XFRecord cf = null; if (!xfRecords.ContainsKey(xfIndex)) { // TODO: CML -- what does THIS actually achieve unless it has side-effects? CellFormat readFormat = fromSheet.getColumnView(j).getFormat(); WritableCellFormat wcf = copyCellFormat(readFormat); } else cf = xfRecords[xfIndex]; cir.setCellFormat(cf); cir.setHidden(rcir.getHidden()); columnFormats.Add(cir); } } // Copy the hyperlinks Hyperlink[] hls = fromSheet.getHyperlinks(); for (int i = 0; i < hls.Length; i++) { WritableHyperlink hr = new WritableHyperlink(hls[i], toSheet); hyperlinks.Add(hr); } // Copy the merged cells Range[] merged = fromSheet.getMergedCells(); for (int i = 0; i < merged.Length; i++) mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet)); // Copy the row properties try { CSharpJExcel.Jxl.Read.Biff.RowRecord[] rowprops = fromSheet.getRowProperties(); for (int i = 0; i < rowprops.Length; i++) { RowRecord rr = toSheet.getRowRecord(rowprops[i].getRowNumber()); XFRecord format = null; CSharpJExcel.Jxl.Read.Biff.RowRecord rowrec = rowprops[i]; if (rowrec.hasDefaultFormat()) { if (!xfRecords.ContainsKey(rowrec.getXFIndex())) { int rownum = rowrec.getRowNumber(); CellFormat readFormat = fromSheet.getRowView(rownum).getFormat(); WritableCellFormat wcf = copyCellFormat(readFormat); } else format = xfRecords[rowrec.getXFIndex()]; } rr.setRowDetails(rowrec.getRowHeight(), rowrec.matchesDefaultFontHeight(), rowrec.isCollapsed(), rowrec.getOutlineLevel(), rowrec.getGroupStart(), format); numRows = System.Math.Max(numRows, rowprops[i].getRowNumber() + 1); } } catch (RowsExceededException e) { // Handle the rows exceeded exception - this cannot occur since // the sheet we are copying from will have a valid number of rows Assert.verify(false); } // Copy the headers and footers // sheetWriter.setHeader(new HeaderRecord(si.getHeader())); // sheetWriter.setFooter(new FooterRecord(si.getFooter())); // Copy the page breaks int[] rowbreaks = fromSheet.getRowPageBreaks(); if (rowbreaks != null) { for (int i = 0; i < rowbreaks.Length; i++) rowBreaks.Add(rowbreaks[i]); } int[] columnbreaks = fromSheet.getColumnPageBreaks(); if (columnbreaks != null) { for (int i = 0; i < columnbreaks.Length; i++) columnBreaks.Add(columnbreaks[i]); } // Copy the charts Chart[] fromCharts = fromSheet.getCharts(); if (fromCharts != null && fromCharts.Length > 0) { //logger.warn("Importing of charts is not supported"); /* sheetWriter.setCharts(fromSheet.getCharts()); IndexMapping xfMapping = new IndexMapping(200); for (Iterator i = xfRecords.keySet().iterator(); i.hasNext();) { Integer key = (Integer) i.next(); XFRecord xfmapping = (XFRecord) xfRecords[key); xfMapping.setMapping(key, xfmapping.getXFIndex()); } IndexMapping fontMapping = new IndexMapping(200); for (Iterator i = fonts.keySet().iterator(); i.hasNext();) { Integer key = (Integer) i.next(); Integer fontmap = (Integer) fonts[key); fontMapping.setMapping(key, fontmap); } IndexMapping formatMapping = new IndexMapping(200); for (Iterator i = formats.keySet().iterator(); i.hasNext();) { Integer key = (Integer) i.next(); Integer formatmap = (Integer) formats[key); formatMapping.setMapping(key, formatmap); } // Now reuse the rationalization feature on each chart to // handle the new fonts for (int i = 0; i < fromCharts.Length ; i++) { fromCharts[i].rationalize(xfMapping, fontMapping, formatMapping); } */ } // Copy the drawings DrawingGroupObject[] dr = fromSheet.getDrawings(); // Make sure the destination workbook has a drawing group // created in it if (dr.Length > 0 && toSheet.getWorkbook().getDrawingGroup() == null) toSheet.getWorkbook().createDrawingGroup(); for (int i = 0; i < dr.Length; i++) { if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Drawing) { WritableImage wi = new WritableImage (dr[i].getX(), dr[i].getY(), dr[i].getWidth(), dr[i].getHeight(), dr[i].getImageData()); toSheet.getWorkbook().addDrawing(wi); drawings.Add(wi); images.Add(wi); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Comment) { CSharpJExcel.Jxl.Biff.Drawing.Comment c = new CSharpJExcel.Jxl.Biff.Drawing.Comment(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(c); // Set up the reference on the cell value CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(),c.getRow()); Assert.verify(cv.getCellFeatures() != null); cv.getWritableCellFeatures().setCommentDrawing(c); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Button) { CSharpJExcel.Jxl.Biff.Drawing.Button b = new CSharpJExcel.Jxl.Biff.Drawing.Button(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(b); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.ComboBox) { CSharpJExcel.Jxl.Biff.Drawing.ComboBox cb = new CSharpJExcel.Jxl.Biff.Drawing.ComboBox(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(cb); } } // Copy the data validations DataValidation rdv = fromSheet.getDataValidation(); if (rdv != null) { dataValidation = new DataValidation(rdv, toSheet.getWorkbook(), toSheet.getWorkbook(), workbookSettings); uint objid = dataValidation.getComboBoxObjectId(); if (objid != 0) comboBox = (ComboBox)drawings[(int)objid]; } // Copy the workspace options sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions()); // Set a flag to indicate if it contains a chart only if (fromSheet.getSheetBof().isChart()) { chartOnly = true; sheetWriter.setChartOnly(); } // Copy the environment specific print record if (fromSheet.getPLS() != null) { if (fromSheet.getWorkbookBof().isBiff7()) { //logger.warn("Cannot copy Biff7 print settings record - ignoring"); } else { plsRecord = new PLSRecord(fromSheet.getPLS()); } } // Copy the button property set if (fromSheet.getButtonPropertySet() != null) { buttonPropertySet = new ButtonPropertySetRecord (fromSheet.getButtonPropertySet()); } importNames(); // Copy the outline levels maxRowOutlineLevel = fromSheet.getMaxRowOutlineLevel(); maxColumnOutlineLevel = fromSheet.getMaxColumnOutlineLevel(); }
/** * Copies a sheet from a read-only version to the writable version. * Performs shallow copies */ public void copySheet() { shallowCopyCells(); // Copy the column info records CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord[] readCirs = fromSheet.getColumnInfos(); for (int i = 0; i < readCirs.Length; i++) { CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord rcir = readCirs[i]; for (int j = rcir.getStartColumn(); j <= rcir.getEndColumn(); j++) { ColumnInfoRecord cir = new ColumnInfoRecord(rcir, j, formatRecords); cir.setHidden(rcir.getHidden()); columnFormats.Add(cir); } } // Copy the hyperlinks Hyperlink[] hls = fromSheet.getHyperlinks(); for (int i = 0; i < hls.Length; i++) { WritableHyperlink hr = new WritableHyperlink (hls[i], toSheet); hyperlinks.Add(hr); } // Copy the merged cells Range[] merged = fromSheet.getMergedCells(); for (int i = 0; i < merged.Length; i++) mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet)); // Copy the row properties try { CSharpJExcel.Jxl.Read.Biff.RowRecord[] rowprops = fromSheet.getRowProperties(); for (int i = 0; i < rowprops.Length; i++) { RowRecord rr = toSheet.getRowRecord(rowprops[i].getRowNumber()); XFRecord format = rowprops[i].hasDefaultFormat() ? formatRecords.getXFRecord(rowprops[i].getXFIndex()) : null; rr.setRowDetails(rowprops[i].getRowHeight(), rowprops[i].matchesDefaultFontHeight(), rowprops[i].isCollapsed(), rowprops[i].getOutlineLevel(), rowprops[i].getGroupStart(), format); numRows = System.Math.Max(numRows, rowprops[i].getRowNumber() + 1); } } catch (RowsExceededException e) { // Handle the rows exceeded exception - this cannot occur since // the sheet we are copying from will have a valid number of rows Assert.verify(false); } // Copy the headers and footers // sheetWriter.setHeader(new HeaderRecord(si.getHeader())); // sheetWriter.setFooter(new FooterRecord(si.getFooter())); // Copy the page breaks int[] rowbreaks = fromSheet.getRowPageBreaks(); if (rowbreaks != null) { for (int i = 0; i < rowbreaks.Length; i++) rowBreaks.Add(rowbreaks[i]); } int[] columnbreaks = fromSheet.getColumnPageBreaks(); if (columnbreaks != null) { for (int i = 0; i < columnbreaks.Length; i++) columnBreaks.Add(columnbreaks[i]); } // Copy the charts sheetWriter.setCharts(fromSheet.getCharts()); // Copy the drawings DrawingGroupObject[] dr = fromSheet.getDrawings(); for (int i = 0; i < dr.Length; i++) { if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Drawing) { WritableImage wi = new WritableImage (dr[i], toSheet.getWorkbook().getDrawingGroup()); drawings.Add(wi); images.Add(wi); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Comment) { CSharpJExcel.Jxl.Biff.Drawing.Comment c = new CSharpJExcel.Jxl.Biff.Drawing.Comment(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(c); // Set up the reference on the cell value CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(), c.getRow()); Assert.verify(cv.getCellFeatures() != null); cv.getWritableCellFeatures().setCommentDrawing(c); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Button) { CSharpJExcel.Jxl.Biff.Drawing.Button b = new CSharpJExcel.Jxl.Biff.Drawing.Button (dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(b); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.ComboBox) { CSharpJExcel.Jxl.Biff.Drawing.ComboBox cb = new CSharpJExcel.Jxl.Biff.Drawing.ComboBox (dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(cb); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.CheckBox) { CSharpJExcel.Jxl.Biff.Drawing.CheckBox cb = new CSharpJExcel.Jxl.Biff.Drawing.CheckBox (dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(cb); } } // Copy the data validations DataValidation rdv = fromSheet.getDataValidation(); if (rdv != null) { dataValidation = new DataValidation(rdv, toSheet.getWorkbook(), toSheet.getWorkbook(), workbookSettings); uint objid = dataValidation.getComboBoxObjectId(); if (objid != 0) comboBox = (ComboBox)drawings[(int)objid]; } // Copy the conditional formats ConditionalFormat[] cf = fromSheet.getConditionalFormats(); if (cf.Length > 0) { for (int i = 0; i < cf.Length; i++) conditionalFormats.Add(cf[i]); } // Get the autofilter autoFilter = fromSheet.getAutoFilter(); // Copy the workspace options sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions()); // Set a flag to indicate if it contains a chart only if (fromSheet.getSheetBof().isChart()) { chartOnly = true; sheetWriter.setChartOnly(); } // Copy the environment specific print record if (fromSheet.getPLS() != null) { if (fromSheet.getWorkbookBof().isBiff7()) { //logger.warn("Cannot copy Biff7 print settings record - ignoring"); } else { plsRecord = new PLSRecord(fromSheet.getPLS()); } } // Copy the button property set if (fromSheet.getButtonPropertySet() != null) { buttonPropertySet = new ButtonPropertySetRecord (fromSheet.getButtonPropertySet()); } // Copy the outline levels maxRowOutlineLevel = fromSheet.getMaxRowOutlineLevel(); maxColumnOutlineLevel = fromSheet.getMaxColumnOutlineLevel(); }
/** * Copies a sheet from a read-only version to the writable version. * Performs shallow copies */ public void copySheet() { shallowCopyCells(); // Copy the column formats foreach (ColumnInfoRecord cv in fromColumnFormats) { toColumnFormats.Add(cv); } // Copy the merged cells Range[] merged = fromMergedCells.getMergedCells(); for (int i = 0; i < merged.Length; i++) { toMergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet)); } try { RowRecord row = null; RowRecord newRow = null; for (int i = 0; i < fromRows.Length; i++) { row = fromRows[i]; if (row != null && (!row.isDefaultHeight() || row.isCollapsed())) { newRow = toSheet.getRowRecord(i); newRow.setRowDetails(row.getRowHeight(), row.matchesDefaultFontHeight(), row.isCollapsed(), row.getOutlineLevel(), row.getGroupStart(), row.getStyle()); } } } catch (RowsExceededException e) { // Handle the rows exceeded exception - this cannot occur since // the sheet we are copying from will have a valid number of rows Assert.verify(false); } // Copy the horizontal page breaks toRowBreaks = new ArrayList(fromRowBreaks); // Copy the vertical page breaks toColumnBreaks = new ArrayList(fromColumnBreaks); // Copy the data validations if (fromDataValidation != null) { toDataValidation = new DataValidation (fromDataValidation, toSheet.getWorkbook(), toSheet.getWorkbook(), toSheet.getWorkbook().getSettings()); } // Copy the charts sheetWriter.setCharts(fromSheet.getCharts()); // Copy the drawings foreach (object o in fromDrawings) { if (o is CSharpJExcel.Jxl.Biff.Drawing.Drawing) { WritableImage wi = new WritableImage ((CSharpJExcel.Jxl.Biff.Drawing.Drawing)o, toSheet.getWorkbook().getDrawingGroup()); toDrawings.Add(wi); toImages.Add(wi); } // Not necessary to copy the comments, as they will be handled by // the deep copy of the individual cells } // Copy the workspace options sheetWriter.setWorkspaceOptions(fromWorkspaceOptions); // Copy the environment specific print record if (fromPLSRecord != null) { toPLSRecord = new PLSRecord(fromPLSRecord); } // Copy the button property set if (fromButtonPropertySet != null) { toButtonPropertySet = new ButtonPropertySetRecord(fromButtonPropertySet); } // Copy the hyperlinks foreach (WritableHyperlink hyperlink in fromHyperlinks) { WritableHyperlink hr = new WritableHyperlink(hyperlink, toSheet); toHyperlinks.Add(hr); } }
/** * Imports a sheet from a different workbook, doing a deep copy */ public void importSheet() { xfRecords = new Dictionary <int, WritableCellFormat>(); fonts = new Dictionary <int, int>(); formats = new Dictionary <int, int>(); deepCopyCells(); // Copy the column info records CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord[] readCirs = fromSheet.getColumnInfos(); for (int i = 0; i < readCirs.Length; i++) { CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord rcir = readCirs[i]; for (int j = rcir.getStartColumn(); j <= rcir.getEndColumn(); j++) { ColumnInfoRecord cir = new ColumnInfoRecord(rcir, j); int xfIndex = cir.getXfIndex(); XFRecord cf = null; if (!xfRecords.ContainsKey(xfIndex)) { // TODO: CML -- what does THIS actually achieve unless it has side-effects? CellFormat readFormat = fromSheet.getColumnView(j).getFormat(); WritableCellFormat wcf = copyCellFormat(readFormat); } else { cf = xfRecords[xfIndex]; } cir.setCellFormat(cf); cir.setHidden(rcir.getHidden()); columnFormats.Add(cir); } } // Copy the hyperlinks Hyperlink[] hls = fromSheet.getHyperlinks(); for (int i = 0; i < hls.Length; i++) { WritableHyperlink hr = new WritableHyperlink(hls[i], toSheet); hyperlinks.Add(hr); } // Copy the merged cells Range[] merged = fromSheet.getMergedCells(); for (int i = 0; i < merged.Length; i++) { mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet)); } // Copy the row properties try { CSharpJExcel.Jxl.Read.Biff.RowRecord[] rowprops = fromSheet.getRowProperties(); for (int i = 0; i < rowprops.Length; i++) { RowRecord rr = toSheet.getRowRecord(rowprops[i].getRowNumber()); XFRecord format = null; CSharpJExcel.Jxl.Read.Biff.RowRecord rowrec = rowprops[i]; if (rowrec.hasDefaultFormat()) { if (!xfRecords.ContainsKey(rowrec.getXFIndex())) { int rownum = rowrec.getRowNumber(); CellFormat readFormat = fromSheet.getRowView(rownum).getFormat(); WritableCellFormat wcf = copyCellFormat(readFormat); } else { format = xfRecords[rowrec.getXFIndex()]; } } rr.setRowDetails(rowrec.getRowHeight(), rowrec.matchesDefaultFontHeight(), rowrec.isCollapsed(), rowrec.getOutlineLevel(), rowrec.getGroupStart(), format); numRows = System.Math.Max(numRows, rowprops[i].getRowNumber() + 1); } } catch (RowsExceededException e) { // Handle the rows exceeded exception - this cannot occur since // the sheet we are copying from will have a valid number of rows Assert.verify(false); } // Copy the headers and footers // sheetWriter.setHeader(new HeaderRecord(si.getHeader())); // sheetWriter.setFooter(new FooterRecord(si.getFooter())); // Copy the page breaks int[] rowbreaks = fromSheet.getRowPageBreaks(); if (rowbreaks != null) { for (int i = 0; i < rowbreaks.Length; i++) { rowBreaks.Add(rowbreaks[i]); } } int[] columnbreaks = fromSheet.getColumnPageBreaks(); if (columnbreaks != null) { for (int i = 0; i < columnbreaks.Length; i++) { columnBreaks.Add(columnbreaks[i]); } } // Copy the charts Chart[] fromCharts = fromSheet.getCharts(); if (fromCharts != null && fromCharts.Length > 0) { //logger.warn("Importing of charts is not supported"); /* * sheetWriter.setCharts(fromSheet.getCharts()); * IndexMapping xfMapping = new IndexMapping(200); * for (Iterator i = xfRecords.keySet().iterator(); i.hasNext();) * { * Integer key = (Integer) i.next(); * XFRecord xfmapping = (XFRecord) xfRecords[key); * xfMapping.setMapping(key, xfmapping.getXFIndex()); * } * * IndexMapping fontMapping = new IndexMapping(200); * for (Iterator i = fonts.keySet().iterator(); i.hasNext();) * { * Integer key = (Integer) i.next(); * Integer fontmap = (Integer) fonts[key); * fontMapping.setMapping(key, fontmap); * } * * IndexMapping formatMapping = new IndexMapping(200); * for (Iterator i = formats.keySet().iterator(); i.hasNext();) * { * Integer key = (Integer) i.next(); * Integer formatmap = (Integer) formats[key); * formatMapping.setMapping(key, formatmap); * } * * // Now reuse the rationalization feature on each chart to * // handle the new fonts * for (int i = 0; i < fromCharts.Length ; i++) * { * fromCharts[i].rationalize(xfMapping, fontMapping, formatMapping); * } */ } // Copy the drawings DrawingGroupObject[] dr = fromSheet.getDrawings(); // Make sure the destination workbook has a drawing group // created in it if (dr.Length > 0 && toSheet.getWorkbook().getDrawingGroup() == null) { toSheet.getWorkbook().createDrawingGroup(); } for (int i = 0; i < dr.Length; i++) { if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Drawing) { WritableImage wi = new WritableImage (dr[i].getX(), dr[i].getY(), dr[i].getWidth(), dr[i].getHeight(), dr[i].getImageData()); toSheet.getWorkbook().addDrawing(wi); drawings.Add(wi); images.Add(wi); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Comment) { CSharpJExcel.Jxl.Biff.Drawing.Comment c = new CSharpJExcel.Jxl.Biff.Drawing.Comment(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(c); // Set up the reference on the cell value CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(), c.getRow()); Assert.verify(cv.getCellFeatures() != null); cv.getWritableCellFeatures().setCommentDrawing(c); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Button) { CSharpJExcel.Jxl.Biff.Drawing.Button b = new CSharpJExcel.Jxl.Biff.Drawing.Button(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(b); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.ComboBox) { CSharpJExcel.Jxl.Biff.Drawing.ComboBox cb = new CSharpJExcel.Jxl.Biff.Drawing.ComboBox(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(cb); } } // Copy the data validations DataValidation rdv = fromSheet.getDataValidation(); if (rdv != null) { dataValidation = new DataValidation(rdv, toSheet.getWorkbook(), toSheet.getWorkbook(), workbookSettings); uint objid = dataValidation.getComboBoxObjectId(); if (objid != 0) { comboBox = (ComboBox)drawings[(int)objid]; } } // Copy the workspace options sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions()); // Set a flag to indicate if it contains a chart only if (fromSheet.getSheetBof().isChart()) { chartOnly = true; sheetWriter.setChartOnly(); } // Copy the environment specific print record if (fromSheet.getPLS() != null) { if (fromSheet.getWorkbookBof().isBiff7()) { //logger.warn("Cannot copy Biff7 print settings record - ignoring"); } else { plsRecord = new PLSRecord(fromSheet.getPLS()); } } // Copy the button property set if (fromSheet.getButtonPropertySet() != null) { buttonPropertySet = new ButtonPropertySetRecord (fromSheet.getButtonPropertySet()); } importNames(); // Copy the outline levels maxRowOutlineLevel = fromSheet.getMaxRowOutlineLevel(); maxColumnOutlineLevel = fromSheet.getMaxColumnOutlineLevel(); }
/** * Copies a sheet from a read-only version to the writable version. * Performs shallow copies */ public void copySheet() { shallowCopyCells(); // Copy the column info records CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord[] readCirs = fromSheet.getColumnInfos(); for (int i = 0; i < readCirs.Length; i++) { CSharpJExcel.Jxl.Read.Biff.ColumnInfoRecord rcir = readCirs[i]; for (int j = rcir.getStartColumn(); j <= rcir.getEndColumn(); j++) { ColumnInfoRecord cir = new ColumnInfoRecord(rcir, j, formatRecords); cir.setHidden(rcir.getHidden()); columnFormats.Add(cir); } } // Copy the hyperlinks Hyperlink[] hls = fromSheet.getHyperlinks(); for (int i = 0; i < hls.Length; i++) { WritableHyperlink hr = new WritableHyperlink (hls[i], toSheet); hyperlinks.Add(hr); } // Copy the merged cells Range[] merged = fromSheet.getMergedCells(); for (int i = 0; i < merged.Length; i++) { mergedCells.add(new SheetRangeImpl((SheetRangeImpl)merged[i], toSheet)); } // Copy the row properties try { CSharpJExcel.Jxl.Read.Biff.RowRecord[] rowprops = fromSheet.getRowProperties(); for (int i = 0; i < rowprops.Length; i++) { RowRecord rr = toSheet.getRowRecord(rowprops[i].getRowNumber()); XFRecord format = rowprops[i].hasDefaultFormat() ? formatRecords.getXFRecord(rowprops[i].getXFIndex()) : null; rr.setRowDetails(rowprops[i].getRowHeight(), rowprops[i].matchesDefaultFontHeight(), rowprops[i].isCollapsed(), rowprops[i].getOutlineLevel(), rowprops[i].getGroupStart(), format); numRows = System.Math.Max(numRows, rowprops[i].getRowNumber() + 1); } } catch (RowsExceededException e) { // Handle the rows exceeded exception - this cannot occur since // the sheet we are copying from will have a valid number of rows Assert.verify(false); } // Copy the headers and footers // sheetWriter.setHeader(new HeaderRecord(si.getHeader())); // sheetWriter.setFooter(new FooterRecord(si.getFooter())); // Copy the page breaks int[] rowbreaks = fromSheet.getRowPageBreaks(); if (rowbreaks != null) { for (int i = 0; i < rowbreaks.Length; i++) { rowBreaks.Add(rowbreaks[i]); } } int[] columnbreaks = fromSheet.getColumnPageBreaks(); if (columnbreaks != null) { for (int i = 0; i < columnbreaks.Length; i++) { columnBreaks.Add(columnbreaks[i]); } } // Copy the charts sheetWriter.setCharts(fromSheet.getCharts()); // Copy the drawings DrawingGroupObject[] dr = fromSheet.getDrawings(); for (int i = 0; i < dr.Length; i++) { if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Drawing) { WritableImage wi = new WritableImage (dr[i], toSheet.getWorkbook().getDrawingGroup()); drawings.Add(wi); images.Add(wi); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Comment) { CSharpJExcel.Jxl.Biff.Drawing.Comment c = new CSharpJExcel.Jxl.Biff.Drawing.Comment(dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(c); // Set up the reference on the cell value CellValue cv = (CellValue)toSheet.getWritableCell(c.getColumn(), c.getRow()); Assert.verify(cv.getCellFeatures() != null); cv.getWritableCellFeatures().setCommentDrawing(c); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.Button) { CSharpJExcel.Jxl.Biff.Drawing.Button b = new CSharpJExcel.Jxl.Biff.Drawing.Button (dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(b); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.ComboBox) { CSharpJExcel.Jxl.Biff.Drawing.ComboBox cb = new CSharpJExcel.Jxl.Biff.Drawing.ComboBox (dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(cb); } else if (dr[i] is CSharpJExcel.Jxl.Biff.Drawing.CheckBox) { CSharpJExcel.Jxl.Biff.Drawing.CheckBox cb = new CSharpJExcel.Jxl.Biff.Drawing.CheckBox (dr[i], toSheet.getWorkbook().getDrawingGroup(), workbookSettings); drawings.Add(cb); } } // Copy the data validations DataValidation rdv = fromSheet.getDataValidation(); if (rdv != null) { dataValidation = new DataValidation(rdv, toSheet.getWorkbook(), toSheet.getWorkbook(), workbookSettings); uint objid = dataValidation.getComboBoxObjectId(); if (objid != 0) { comboBox = (ComboBox)drawings[(int)objid]; } } // Copy the conditional formats ConditionalFormat[] cf = fromSheet.getConditionalFormats(); if (cf.Length > 0) { for (int i = 0; i < cf.Length; i++) { conditionalFormats.Add(cf[i]); } } // Get the autofilter autoFilter = fromSheet.getAutoFilter(); // Copy the workspace options sheetWriter.setWorkspaceOptions(fromSheet.getWorkspaceOptions()); // Set a flag to indicate if it contains a chart only if (fromSheet.getSheetBof().isChart()) { chartOnly = true; sheetWriter.setChartOnly(); } // Copy the environment specific print record if (fromSheet.getPLS() != null) { if (fromSheet.getWorkbookBof().isBiff7()) { //logger.warn("Cannot copy Biff7 print settings record - ignoring"); } else { plsRecord = new PLSRecord(fromSheet.getPLS()); } } // Copy the button property set if (fromSheet.getButtonPropertySet() != null) { buttonPropertySet = new ButtonPropertySetRecord (fromSheet.getButtonPropertySet()); } // Copy the outline levels maxRowOutlineLevel = fromSheet.getMaxRowOutlineLevel(); maxColumnOutlineLevel = fromSheet.getMaxColumnOutlineLevel(); }