工具欄
// 按鈕不可按 tool.SharedProps.Enabled = false;
Grid
// Grid中記錄時間 // 建議SQL Server中使用字符字段(沒有深入測試,只是字符字段可行),然后設置Grid的屬性中,列的Style屬性為Time或TimeWithSpin // 使用代碼為Grid列排序 // 應該先將所有列的VisiblePosition設置為0,再重新設置每一列的值;而且要先從前往后的順序排列。 // 表格 // 是否允許修改 ltGrid1.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.False; // 是否允許換行 ltGrid1.DisplayLayout.Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.False; // 多層表格下,第2層表格不顯示列頭,第1層表格只在第一行顯示列頭 ltGrid1.DisplayLayout.Bands[0].Override.HeaderPlacement = HeaderPlacement.FixedOnTop; ltGrid1.DisplayLayout.Bands[1].ColHeadersVisible = false; // 列 // 新綁定的數據列是否顯示對應表格列 ltGrid1.DisplayLayout.NewColumnLoadStyle = NewColumnLoadStyle.Hide; // 禁止列進行排序 ltGrid1.DisplayLayout.Bands[0].Columns["總庫存"].SortIndicator = SortIndicator.Disabled; // 在bool類型的列上,顯示全選按鈕 ultraGridColumn423.Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always; // 最后一列填充滿Grid ltGrid1.DisplayLayout.AutoFitStyle = AutoFitStyle.ExtendLastColumn; // 顯示合計 summarySettings1.DisplayFormat = "{0}"; summarySettings1.GroupBySummaryValueAppearance = appearance2; summarySettings1.ShowCalculatingText = Infragistics.Win.DefaultableBoolean.False; summarySettings1.SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.BottomFixed; ultraGridBand1.Summaries.AddRange(new Infragistics.Win.UltraWinGrid.SummarySettings[] {summarySettings1}); ultraGridBand1.SummaryFooterCaption = ""; // 行 // Grid中獲取過濾后的行 UltraGridRow[] rows = grid.Rows.GetFilteredInNonGroupByRows(); // 單元格 // 某個單元格是否可以修改 ltGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit; // 某個單元格的顏色 ltGrid1.DisplayLayout.Bands[0].Columns[0].CellAppearance.BackColor = Color.Aqua; // 允許樹狀結構 grid1.DisplayLayout.ViewStyle = ViewStyle.MultiBand; // 設置最大層數 grid1.DisplayLayout.MaxBandDepth = 2; // 樹狀結構展開和收縮 foreach (var row in ltGrid1.Rows) { row.Expanded = true; row.ExpandAll(); row.CollapseAll(); }
Excel導出
// 打開保存窗口,得到保存文件路徑 String fileName = ""; SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = txtAssmItemNoPrefix.Text; // 默認文件名 dialog.Filter = "Excel Worksheets|*.xls"; // 文件類型過濾器 if (dialog.ShowDialog() == DialogResult.OK) fileName = dialog.FileName; dialog.Dispose(); // 可以把Excel模版放到資源文件中 var buffer = Properties.Resources.Excel模版; using (Stream output = File.OpenWrite(fileName)) { output.Write(buffer, 0, buffer.Length); } // 打開Excel表 Workbook workbook = Workbook.Load(fileName); // 選擇工作表 Worksheet sheetHeader = workbook.Worksheets[0]; // 去掉合並單元格 sheetHeader.MergedCellsRegions.Remove(sheetHeader.Rows[0].GetCellAssociatedMergedCellsRegion(0)); // 增加合並單元格 WorksheetMergedCellsRegion sheetRegion = sheetHeader.MergedCellsRegions.Add(0, 0, 0, 12); // 合並單元格賦值 sheetRegion.Value = "標題1"; // 水平居中 sheetRegion.CellFormat.Alignment = HorizontalCellAlignment.Center; // 垂直居中 sheetRegion.CellFormat.VerticalAlignment = VerticalCellAlignment.Center; // 自動換行 sheetRegion.CellFormat.WrapText = ExcelDefaultableBoolean.True; // 行高 sheetHeader.Rows[1].Height = sheetHeader.Rows[1].Height * 3; // 行和列都是從0開始 // 單元格賦值 sheetHeader.Rows[1].Cells[1].Value = DateTime.Now;//訂貨日期 sheetHeader.Rows[1].Cells[2].Value = "文字";//銷售員 // 水平居中 sheetHeader.Rows[1].Cells[2].CellFormat.Alignment = HorizontalCellAlignment.Center; // 垂直居中 sheetHeader.Rows[1].Cells[2].CellFormat.VerticalAlignment = VerticalCellAlignment.Center; // 自動換行 sheetHeader.Rows[1].Cells[2].CellFormat.WrapText = ExcelDefaultableBoolean.True; // 保存Excel workbook.Save(fileName);
