Sunday, April 02, 2006

ExcelXmlWriter Code Correction

I was not proof-reading well when I sent out that post on ExcelXmlWriter.

Here is the correct code for generating the summary history section.  Sorry about the mixup!

private void CreateHistoryReportSection(WorksheetCollection sheets)


    //reps is a private member ArrayList holding sales reps' last names



    WorksheetRow row;

    WorksheetCell cell;

    string repName;


    Worksheet history = sheets["History"];


    WorksheetColumn repCol = history.Table.Columns.Add();

    repCol.Width = 80;

    repCol.Index = 8;


    WorksheetColumn figures = history.Table.Columns.Add();

    figures.Width = 80;

    figures.Index = 9;


    row = history.Table.Rows[0];

    row.Cells.Add();        //blank cell to get alignment right

    row.Cells.Add("Sales Rep", DataType.String, "headerStyle");

    row.Cells.Add("Total Sales", DataType.String, "headerStyle");


    for (int i = 0; i < reps.Count; i++)


        row = history.Table.Rows[i + 1]; //offset by one row down

        repName = reps[i].ToString();

        //add and style the rep's name


        cell = row.Cells.Add(repName);

        cell.StyleID = "reportStyle";

        //add a cell and include the summing formula

        cell = row.Cells.Add();

        cell.Formula = "=SUMIF(C[-8],\"" + repName + "\",C[-3])";

        cell.StyleID = "reportStyle";



No comments:

Subscribe (RSS)

The Leadership Journey