public class reportsummary { public void createheader() { var header = new list<keyvaluepair<string, string>> { new keyvaluepair<string, string>("description", "summary role*"), new keyvaluepair<string, string>("colname1" , "public"), new keyvaluepair<string, string>("colname2" , "non public"), new keyvaluepair<string, string>("colname3" , "public"), new keyvaluepair<string, string>("colname4" , "non public"), new keyvaluepair<string, string>("colname5" , "public"), new keyvaluepair<string, string>("colname6" , "non public"), new keyvaluepair<string, string>("colname7" , "public"), new keyvaluepair<string, string>("colname8" , "non public"), new keyvaluepair<string, string>("colname9" , "public"), new keyvaluepair<string, string>("colname10" , "non public"), new keyvaluepair<string, string>("colname11" , "public"), new keyvaluepair<string, string>("colname12" , "non public") }; (int index = 0; index < header.count; index++) { row[index] = header[index].value; } addrow(_currentrow, row, rowstyleindex); } void addrow(int rowindex, object[] cells, params int[] styleindexes) { if (cells != null) { (int columnindex = 0; columnindex < cells.length; columnindex++) { int styleindex = 16; //if style idex defined, pass it, or else pass default style index 16, bold header white background if (styleindexes != null) { styleindex = styleindexes[columnindex]; } addcell((uint)rowindex, columnindex + 1, cells[columnindex], styleindex); } } } }`
class excelprocessor :
public class excelprocessor2010 { protected cell addcell(uint rowindex, int columnindex, object cellvalue, int styleindex) { //removing values greyed out cell , empty cell if (string.isnullorempty(convert.tostring(cellvalue)) || styleindex == 33) { cellvalue = " "; } cell cell = addcell(rowindex, columnindex, cellvalue); cell.styleindex = (uint)styleindex; return cell; } protected cell addcell(uint rowindex, int columnindex, object cellvalue) { cell cell = null; if (cellvalue != null) { string cellvalueasstring = cellvalue.tostring(); if (!string.isnullorempty(cellvalueasstring)) { cell = insertcellinworksheet(getcolumnname(columnindex), rowindex); if ((cellvalue bool || cellvalue bool?)) { cell.datatype = cellvalues.boolean; } else if (cellvalue datetime || cellvalue datetime?) { cell.datatype = cellvalues.date; } else if (cellvalue string && !string.isnullorempty((string)cellvalue)) { cell.datatype = cellvalues.sharedstring; } else if (cellvalue byte || cellvalue byte? || cellvalue sbyte || cellvalue sbyte? || cellvalue short || cellvalue short? || cellvalue ushort || cellvalue ushort? || cellvalue int || cellvalue int? || cellvalue uint || cellvalue uint? || cellvalue long || cellvalue long? || cellvalue ulong || cellvalue ulong? || cellvalue float || cellvalue float? || cellvalue double || cellvalue double? || cellvalue decimal || cellvalue decimal? ) { cell.datatype = cellvalues.number; } if (cell.cellvalue == null) { cell.append(new cellvalue { text = cell.datatype != cellvalues.sharedstring ? cellvalueasstring : insertsharedstringitem(cellvalueasstring) }); } else { cell.cellvalue.text = cellvalueasstring; } } } return cell; } protected string insertsharedstringitem(string text) { // if part not contain sharedstringtable, create one. if (sharedstringtablepart.sharedstringtable == null) { sharedstringtablepart.sharedstringtable = new sharedstringtable(); } int = 0; // iterate through items in sharedstringtable. if text exists, return index. foreach (sharedstringitem item in sharedstringtablepart.sharedstringtable.elements<sharedstringitem>()) { if (item.innertext == text) { return i.tostring(); } i++; } // text not exist in part. create sharedstringitem , return index. sharedstringtablepart.sharedstringtable.appendchild(new sharedstringitem(new text(text))); //sharedstringtablepart.sharedstringtable.save(); return i.tostring(); } }
i generating excel file using openxml. trying create table in excel shown in image:
but changing column headers public/nonpublic public1, nonpublic2, public3, nonpublic4 etc... after research understood excel expecting unique column headers. it's happening when create excel using openxml. if create excel manually , set headers these works fine.
can me on this?
Comments
Post a Comment