Beispiel #1
0
        private void listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListView    lv    = (ListView)sender;
            ReportTable table = null;

            foreach (ListViewItem item in lv.SelectedItems)
            {
                table = item.Tag as ReportTable;
            }
            if (table == null)
            {
                return;
            }
            dataView.Columns.Clear();
            dataView.Rows.Clear();
            dataView.Visible = false;
            char ch = 'A';

            for (int i = 0; i < table.col; i++)
            {
                dataView.Columns.Add(i.ToString(), ch.ToString());
                dataView.Rows.Add(table.row);
                for (int j = 0; j < table.row; j++)
                {
                    this.dataView[i, j].Value = table.dataArray[j][i];
                }
                ch++;
            }
            dataView.Visible = true;
        }
        private List <ReportTable> ReadAllTableFromSheet(Excel.Worksheet sheet)
        {
            int col      = sheet.UsedRange.Columns.Count;
            int totalRow = sheet.UsedRange.Rows.Count;

            //从第二列开始,便于发现表的第一行
            Excel.Range startCell = sheet.Cells[1, 2];
            startCell = startCell.End[Excel.XlDirection.xlDown];
            string             value  = startCell.Value;
            List <ReportTable> tables = new List <ReportTable>();

            while (value != null && value.Length != 0)
            {
                ReportTable table = new ReportTable();
                table.LoadDataArrayFromRange(sheet.Range[
                                                 startCell.Offset[0, -1],
                                                 startCell.End[Excel.XlDirection.xlDown].End[Excel.XlDirection.xlToRight]
                                             ]
                                             );
                tables.Add(table);
                regions.Add(table.region);
                startCell =
                    startCell.End[Excel.XlDirection.xlDown].End[Excel.XlDirection.xlDown];
                value = startCell.Value;
            }
            return(tables);
        }
Beispiel #3
0
        private PowerPoint.Chart BuildChart(ReportTable table, int page, int chartid, RowFilter filter)
        {
            PowerPoint.Slide slide = ppt.ActivePresentation.Slides[page];
            PowerPoint.Chart chart = slide.Shapes[chartid].Chart;
            chart.ChartData.Activate();
            Excel.Workbook  book  = chart.ChartData.Workbook;
            Excel.Worksheet sheet = book.Worksheets[1];

            //清空现有的数据
            sheet.Cells.Clear();


            int insertRow = 0;

            string[,] ta = new string[table.dataArray.Length, table.dataArray[0].Length];
            for (int i = 0; i < table.dataArray.Length; i++)
            {
                string[] row         = table.dataArray[i];
                string[] filteredRow = i == 0 ? row : filter(row);
                if (filteredRow != null)
                {
                    for (int j = 0; j < filteredRow.Length; j++)
                    {
//                        ta[insertRow, j] = filteredRow[j];
                        sheet.Cells[insertRow + 1, j + 1].Value = filteredRow[j];
                    }
                    insertRow++;
                }
            }
            Excel.Range tableRange =
                sheet.Range[sheet.Cells[1, 1],
                            sheet.Cells[insertRow, table.dataArray[0].Length]];
            //tableRange.Value = ta;

            string addr = tableRange.Address;

            chart.SetSourceData(sheet.Name + "!" + tableRange.Address, PowerPoint.XlRowCol.xlRows);

            book.Close();
            return(chart);
        }