private void ViewReport_Load(object sender, EventArgs e) { //sheet.InsertColumns(0,23); dataReport = new DataReportLogic(); selects = new List <Company>(); InitHeader(); sheet = excel.CurrentWorksheet; sheet.DeleteRows(0, 2);//删除模板1、2行 //LoadData(); LoadSelectItems(); sheet.SetCols(22); sheet.Resize(200, 22); sheet.BeforeCellEdit += (s, ev) => ev.IsCancelled = true; if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } ExcelHelper.SetDecimalFormat(sheet, 2); sheet.AutoFitColumnWidth(0, false); }
/// <summary> /// Data records collection changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Records_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // Changed event, _Records has got action result switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: { foreach (IRecordModel item in e.NewItems) { AddOrUpdateOneFromRecord(_Records.Count - 1, item); } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: { foreach (IRecordModel item in e.OldItems) { int rowIndex = item.RowIndex; _Worksheet.DeleteRows(rowIndex, 1); for (int i = rowIndex; i < _Records.Count; i++) { _Records.ElementAt(rowIndex).RowIndex = rowIndex; } } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Replace: { for (int i = 0; i < e.NewItems.Count; i++) { IRecordModel item = e.NewItems[i] as IRecordModel; int rowIndex = (e.OldItems[i] as IRecordModel).RowIndex; AddOrUpdateOneFromRecord(rowIndex, item); } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Move: { for (int i = 0; i < _Records.Count; i++) { IRecordModel item = _Records.ElementAt(i); int rowIndex = item.RowIndex; if (rowIndex != i) { AddOrUpdateOneFromRecord(i, item); } } break; } case System.Collections.Specialized.NotifyCollectionChangedAction.Reset: { _Worksheet.DeleteRows(0, _Worksheet.UsedRange.Rows); break; } default: break; } }