public object Clone() { CellFormat cf = new CellFormat(); cf.CellColor = this.CellColor; cf.CellFont = (Font)this.CellFont.Clone(); cf.TextColor = this.TextColor; cf.IsDefault = this.IsDefault; cf.CellHeight = this.CellHeight; cf.CellWidth = this.CellWidth; return cf; }
public static CellFormat createCellFormat(string settings) { string[] s = settings.Split(','); CellFormat c = new CellFormat(); FontStyle style = (((int.Parse(s[(int)SettingPosition.Bold]) == 1)? FontStyle.Bold : 0) | ((int.Parse(s[(int)SettingPosition.Italic]) == 1)? FontStyle.Italic : 0) | ((int.Parse(s[(int)SettingPosition.Underline]) == 1)? FontStyle.Underline : 0)); c.CellColor = Color.FromArgb(int.Parse(s[(int)SettingPosition.CellColor])); c.TextColor = Color.FromArgb(int.Parse(s[(int)SettingPosition.TextColor])); c.CellFont = FontFactory.CreateFont(s[(int)SettingPosition.FontFamily], float.Parse(s[(int)SettingPosition.FontSize]), style); return c; }
public Cell(string formula, CellFormat cellFormat) { Formula = formula; CellFormat = cellFormat; }
public Cell(CellFormat cellFormat) : this(null, cellFormat) { }
private bool WriteBook() { Cell theCell = new Cell(); Cell defaultCell = new Cell(); Cell tempCell = new Cell(); /**** TEST Code*/ CellCollection cc = new CellCollection(); FontFamily blahFamily = new FontFamily("Arial"); Font blahFont = new Font(blahFamily, 13); CellFormat blahFormat = new CellFormat(blahFont,Color.Orange, Color.Green); Font f = new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Bold); f = new Font(f, f.Style | FontStyle.Italic); CellFormat blahFormat2 = new CellFormat(f, Color.Black, Color.Black); //blahFormat.CellColor = Color.Yellow; //blahFormat.TextColor = Color.Purple; //tempCell.CellFormat = blahFormat; cc[0, 0] = new Cell("= SUM()", blahFormat); cc[0, 0].Value = "42"; cc[0, 1] = new Cell("", tempCell.CellFormat); cc[0, 2] = new Cell("", tempCell.CellFormat); cc[1, 0] = new Cell("", tempCell.CellFormat); cc[1, 0].Value = "blah"; cc[1, 1] = new Cell("= AVG()", tempCell.CellFormat); cc[1, 1].Value = "47"; cc[1, 2] = new Cell("", blahFormat2); cc[1, 2].Value = "99"; cc[2, 0] = new Cell("", tempCell.CellFormat); cc[2, 0].Value = "YourMother"; cc[2, 1] = new Cell("", tempCell.CellFormat); cc[2, 2] = new Cell("", tempCell.CellFormat); book[0] = new SpreadsheetModel(cc); //Cell theCell = new Cell(); //END TEST CODE double tempDouble = new double(); bool blank = false; fileStream = new FileStream(filename, FileMode.Create); textWriter = new XmlTextWriter(fileStream, Encoding.Unicode); try { textWriter.WriteStartElement(filename.Substring(filename.LastIndexOf("\\") + 1, filename.LastIndexOf(".") - filename.LastIndexOf("\\") - 1)); textWriter.WriteStartElement("sheet"); textWriter.WriteStartElement("author"); textWriter.WriteAttributeString("name", "Nathan Benjamin"); textWriter.WriteEndElement(); textWriter.WriteString(Environment.NewLine + "other metadata" + Environment.NewLine); int bookRows = book[0].Cells.Rows; int bookColumns = book[0].Cells.Columns; for (int column = 0; column < bookColumns; column++) { textWriter.WriteStartElement("column"); textWriter.WriteAttributeString("index", column.ToString()); for (int row = 0; row < bookRows; row++) { theCell = book[0].Cells[row, column]; /*IS CELL DEFAULT CHECK*/ blank = false; if (theCell.Value == null) { blank = true; } else if (theCell.Value.Equals("")) { blank = true; } /*CELL FORMAT needs to be instantiated*/ //if (theCell.CellFormat.IsDefault == false) { blank = true; } if (blank == true) {//skip writing the row, go on to the next cell. } else { textWriter.WriteStartElement("row"); textWriter.WriteAttributeString("index", row.ToString()); if (theCell != null) { /*CONTENT TYPE CHECK*/ textWriter.WriteStartElement("content"); if (theCell.Formula.Contains("=")) { textWriter.WriteAttributeString("type", "Formula"); } else { try { tempDouble = double.Parse(theCell.Value); textWriter.WriteAttributeString("type", "Number"); } catch (System.FormatException e) { textWriter.WriteAttributeString("type", "Text"); } } /*IF THE CELLFORMAT IS DEFAULT, WE WRITE NOTHING ABOUT CELL FORMAT if(theCell.CellFormat.IsDefault){//skip the cell } else{*/ //Each Format attribute is compared to the default cell. If that .Equals method returns false //Then theCell has an attribute different from defaultCell, and that attribute must be written. //CellColor if (theCell.CellFormat.CellColor.Equals(defaultCell.CellFormat.CellColor) == false) textWriter.WriteAttributeString("CellColor", theCell.CellFormat.CellColor.ToString()); //TextColor if (theCell.CellFormat.TextColor.Equals(defaultCell.CellFormat.TextColor) == false) textWriter.WriteAttributeString("TextColor", theCell.CellFormat.TextColor.ToString()); //Bold if (theCell.CellFormat.CellFont.Bold.Equals(defaultCell.CellFormat.CellFont.Bold) == false) textWriter.WriteAttributeString("Bold", "true"); //Italics if (theCell.CellFormat.CellFont.Italic.Equals(defaultCell.CellFormat.CellFont.Italic) == false) textWriter.WriteAttributeString("Italic", "true"); //Underline if (theCell.CellFormat.CellFont.Underline.Equals(defaultCell.CellFormat.CellFont.Underline) == false) textWriter.WriteAttributeString("Underline", "true"); //FontFamily if (theCell.CellFormat.CellFont.FontFamily.Equals(defaultCell.CellFormat.CellFont.FontFamily) == false) textWriter.WriteAttributeString("FontFamily", theCell.CellFormat.CellFont.FontFamily.ToString()); //Size if (theCell.CellFormat.CellFont.Size.Equals(defaultCell.CellFormat.CellFont.Size) == false) textWriter.WriteAttributeString("Size", theCell.CellFormat.CellFont.Size.ToString()); /*}//end of Format Check */ //FORMULA CHECK if (theCell.Formula.Equals("") || theCell.Formula.Equals(null)) {} //ignore else{ textWriter.WriteElementString("Formula", theCell.Formula.ToString()); } //VALUE CHECK if (theCell.Value.Equals("") || theCell.Value.Equals(null)) { } //ignore else { textWriter.WriteElementString("Value", theCell.Value.ToString()); } textWriter.WriteEndElement();//end of content type element? }//end of theCell != null if /*****Where do all these other write elements correspond to?*/ textWriter.WriteEndElement(); }//end of blank cell check if/else }//end of row loop textWriter.WriteEndElement(); }//end of column loop textWriter.WriteEndElement(); textWriter.WriteEndElement(); textWriter.Flush(); } catch (Exception e) { MessageBox.Show("Error: (" + e.GetType().ToString() + "): " + e.Message + Environment.NewLine + "Debug Data: " + e.ToString(), "Error"); } finally { if (textWriter != null) { textWriter.Close(); textWriter = null; } } return true; }
public Cell() { CellFormat = new CellFormat(new Font("Times", 12), Color.Black, Color.White); }
public Cell(string formula, CellFormat cellFormat) { Error = false; Formula = formula; CellFormat = cellFormat; }