/// <summary> /// Cell에 Fomula셑팅을 한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="cell"></param> /// <param name="formulaString"></param> /// <param name="celltype">변경할 셀 타입 FarPoint.Win.Spread.CellType 네임스페이스에서 새로운 클래스생성 하여 넘긴다. 무변경 null</param> public static void Invoke_CellFormula_Set(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, FarPoint.Win.Spread.Cell cell, string formulaString, FarPoint.Win.Spread.CellType.BaseCellType celltype) { if (fp.InvokeRequired) { fp.BeginInvoke(new delInvoke_CellFormula_Set(Invoke_CellFormula_Set), new object[] { fp, sv, cell, formulaString, celltype }); return; } string textvalue = string.Empty; cell.Formula = formulaString; if (celltype != null) { cell.CellType = celltype; } /* * textvalue = cell.Text; * FarPoint.Win.Spread.CellType.TextCellType t = new FarPoint.Win.Spread.CellType.TextCellType(); * cell.CellType = t; * cell.Formula = ""; * cell.Value = textvalue; */ }
private void ShowData() { Cursor = Cursors.WaitCursor; DataSet dataSet = Erp.BusinessManager.설비.Get설비등록대장(); FarPoint.Win.Spread.SheetView sheetView = fpSpread등록대장인쇄.ActiveSheet; sheetView.RowCount = 6; int lastrow = 0; int cnt = 1; foreach (DataRow dataRow in dataSet.Tables[0].Rows) { int row = sheetView.RowCount++; sheetView.Cells[row, 0].Value = cnt++; sheetView.Cells[row, 1].Value = dataRow["관리번호"].ToString(); sheetView.Cells[row, 2].Value = dataRow["품명"].ToString(); sheetView.Cells[row, 3].Value = dataRow["규격"].ToString(); sheetView.Cells[row, 4].Value = dataRow["제조회사"].ToString(); sheetView.Cells[row, 5].Value = Convert.ToDateTime(dataRow["구입일자"]).ToString("yyyy-MM-dd"); sheetView.Cells[row, 6].Value = Convert.ToInt32(dataRow["금액"]); sheetView.Cells[row, 7].Value = dataRow["설치장소"].ToString(); sheetView.Cells[row, 8].Value = dataRow["등급"].ToString(); sheetView.Cells[row, 9].Value = dataRow["관리부서"].ToString(); sheetView.Cells[row, 10].Value = dataRow["관리책임자"].ToString(); sheetView.Cells[row, 11].Value = dataRow["수리업체"].ToString(); sheetView.Cells[row, 12].Value = dataRow["수리업체연락처"].ToString(); DrawBorder(row); lastrow = row; } DrawLastRowBorder(lastrow); Cursor = Cursors.Default; }
/// <summary> /// 스프레드에서 원하는 값을 찾는다. /// </summary> /// <param name="sv"></param> /// <param name="strFindValue"></param> /// <param name="intColumns"></param> /// <returns></returns> public static int[] FindData(FarPoint.Win.Spread.SheetView sv, string strFindValue, int[] intColumns) { Queue <int> q = new Queue <int>(); for (int row = 0; row < sv.Rows.Count; row++) { foreach (int col in intColumns) { if (sv.Cells[row, col].Text.ToUpper() == strFindValue.ToUpper()) { q.Enqueue(row); continue; } } } if (q.Count < 1) { return(null); } else { int[] j = new int[q.Count]; int i = 0; while (q.Count > 0) { j[i] = q.Dequeue(); i++; } return(j); } }
/// <summary> /// 设置 在当前活动SheetView内 简单下拉列表显示 /// </summary> /// <param name="sheetView">欲显示的SheetView</param> /// <param name="al">列表数组</param> /// <param name="iColumnIndex">需显示本列表的列</param> public void SetColumnList(FarPoint.Win.Spread.SheetView sheetView, ArrayList al, params int[] iColumnIndex) { if (this.Lists == null) { this.Lists = new ArrayList(); } int iListIndex = this.Lists.Count; this.listBoxEnabled = true; InputMap im; im = base.GetInputMap(InputMapMode.WhenAncestorOfFocused); im.Put(new Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.None); Neusoft.FrameWork.WinForms.Controls.PopUpListBox obj = new Neusoft.FrameWork.WinForms.Controls.PopUpListBox(); obj.AddItems(al); this.Controls.Add(obj); obj.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; obj.Size = new System.Drawing.Size(this.intWidth, this.intHeight); obj.Visible = false; this.Lists.Add(obj); string str = ""; foreach (int i in iColumnIndex) { str = string.Format("{0}|{1}{2}", iListIndex.ToString(), sheetView.SheetName, i.ToString()); if (this.sheetList == null) { this.sheetList = new ArrayList(); } else { if (this.JudgeListRow(i)) //原来在该列设置过弹出列表 则覆盖原有实现 { string tempStr = sheetView.SheetName + i.ToString(); string tempListStr = ""; foreach (string info in this.sheetList) { if (info.Substring(info.IndexOf("|") + 1) == tempStr) { tempListStr = info; break; } } if (tempListStr != "") { this.sheetList.Remove(tempListStr); } } } this.sheetList.Add(str); } }
/// <summary> /// 바인딩된 해당 row의 datarowview를 리턴한다. /// </summary> /// <param name="sv"></param> /// <param name="intRowIndexs">null 이면 선택된 row</param> /// <returns></returns> public static DataRowView[] DataBind_GetSelected_Rowviews(FarPoint.Win.Spread.SheetView sv, int [] intRowIndexs) { if (sv.DataSource == null) { return(null); } //datasource를 dataview로 변환 DataView dv = sv.DataSource as DataView; if (dv == null) { DataSet ds = sv.DataSource as DataSet; if (ds != null) { dv = ds.Tables[sv.DataMember].DefaultView; } else { dv = ((DataTable)sv.DataSource).DefaultView; } } if (dv == null) { return(null); } DataRowView[] drvs; int intCnt; if (intRowIndexs == null) { intCnt = sv.ActiveRow.Index2 - sv.ActiveRow.Index + 1; drvs = new DataRowView[intCnt]; for (int i = 0; i < intCnt; i++) { drvs[i] = dv[sv.ActiveRow.Index + i]; } return(drvs); } else { intCnt = intRowIndexs.Length; drvs = new DataRowView[intCnt]; for (int i = 0; i < intCnt; i++) { drvs[i] = dv[intRowIndexs[i]]; } return(drvs); } }
private void fpSpread1_MouseWheel(object sender, MouseEventArgs e) { FarPoint.Win.Spread.SheetView sheetView = (sender as FarPoint.Win.Spread.FpSpread).ActiveSheet; if (sheetView.ColumnCount > 2 && (sheetView.ActiveColumnIndex < sheetView.ColumnCount - 1 && sheetView.ActiveColumnIndex > 0)) { zoom += (e.Delta < 0 ? -0.2 : 0.2); SetGridArea(zoom); } }
/// <summary> /// 원하는 셀을 보여 준다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="row"></param> /// <param name="col"></param> public static void Invoke_ShowCell(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int row, int col) { if (fp.InvokeRequired) { fp.BeginInvoke(new delShowCell(Invoke_ShowCell), new object[] { fp, sv, row, col }); return; } sv.SetActiveCell(row, col, true); fp.ShowActiveCell(VerticalPosition.Center, HorizontalPosition.Center); }
/// <summary> /// row count를 변경한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="intRowCount"></param> public static void Invoke_RowCount(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int intRowCount) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_RowCount(Invoke_RowCount), new object[] { fp, sv, intRowCount }); return; } sv.RowCount = intRowCount; }
/// <summary> /// 셀 범위에 값을 변경한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="Y"></param> /// <param name="X"></param> /// <param name="Y2"></param> /// <param name="X2"></param> /// <param name="objValue"></param> public static void Invoke_CellRange_Value(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int Y, int X, int Y2, int X2, object objValue) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_CellRange_Value(Invoke_CellRange_Value), new object[] { fp, sv, Y, X, Y2, X2, objValue }); return; } sv.Cells[Y, X, Y2, X2].Value = objValue; }
/// <summary> /// 셀을 스팬(머지) 한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="intRow"></param> /// <param name="intCol"></param> /// <param name="intRowSpanCnt"></param> /// <param name="intColSpanCnt"></param> public static void Invoke_CellSpan(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int intRow, int intCol, int intRowSpanCnt, int intColSpanCnt) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_CellSpan(Invoke_CellSpan), new object[] { fp, sv, intRow, intCol, intRowSpanCnt, intColSpanCnt }); return; } sv.Cells[intRow, intCol].ColumnSpan = intColSpanCnt; sv.Cells[intRow, intCol].RowSpan = intRowSpanCnt; }
/// <summary> /// fpSheet에 Row를 추가 하여준다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="intAddIndex">들어갈 위치 : '-1'이면 마지막에 위치 시킨다.</param> /// <param name="intMaxRowCount">최대 행 유지 갯수 : 0이면 무제한 증가..</param> public static void Invoke_AddRowData(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int intAddIndex, int intMaxRowCount, object [] objData) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_AddRowData(Invoke_AddRowData), new object[] { fp, sv, intAddIndex, intMaxRowCount, objData }); return; } try { if (intAddIndex < 0) { intAddIndex = sv.Rows.Count; } sv.Rows.Add(intAddIndex, 1); int intCol = 0; foreach (object obj in objData) { //if (sv.ColumnCount <= intCol) break; sv.Cells[intAddIndex, intCol].Value = obj; intCol++; } //최대행 유지를 위해 Row를 삭제 한다. if (intMaxRowCount > 0 && sv.Rows.Count >= intMaxRowCount) { int intDelIndex = 0; int intDelCount = 1 + intMaxRowCount - sv.Rows.Count; //아래 추가 시만 위에 삭제, 그외 경우는 아래 부분 삭제.. if (intAddIndex < 0) { intDelIndex = 0; } else { intDelIndex = sv.Rows.Count - intDelCount; } sv.Rows.Remove(intDelIndex, 1); } } catch (Exception ex) { log.WLog_Exception(string.Format("Invoke_AddRowData[fp]{0}[AddIdx]{1}[MaxRow]{2}", fp.Name, intAddIndex, intMaxRowCount), ex); } }
/// <summary> /// 获取当前cell是否有下拉列表 /// </summary> /// <param name="view"></param> /// <param name="col"></param> /// <returns></returns> public Neusoft.FrameWork.WinForms.Controls.NeuListBoxPopup GetCurrentList(FarPoint.Win.Spread.SheetView view, int col) { string name = view.SheetName + "_" + col.ToString(); for (int i = 0; i < this.Lists.Length; i++) { if (this.Lists[i] != null && (this.Lists[i] as Neusoft.FrameWork.WinForms.Controls.NeuListBox).Name == name) { return(this.Lists[i]); } } return(null); }
/// <summary> /// 设定那一列显示/不显示ID 编码 成功返回 1 失败返回 0 /// </summary> /// <param name="col"></param> /// <param name="IsVisiable"></param> /// <returns></returns> public int SetIDVisiable(FarPoint.Win.Spread.SheetView view, int col, bool IsVisiable) { //string name = view.SheetName + "_" + col.ToString(); //for (int i = 0; i < this.Lists.Length; i++) //{ // if (this.Lists[i] != null && (this.Lists[i] as Neusoft.FrameWork.WinForms.Controls.NeuListBoxPopup).Name == name) // { // Lists[i].IsShowID = IsVisiable; // return 1; // } //} return(0); }
private void Show중요부품품목Data(DataTable datatable) { FarPoint.Win.Spread.SheetView sheetView = fpSpread설비이력.ActiveSheet; int cnt = 0; foreach (DataRow dataRow in datatable.Rows) { cnt++; sheetView.Cells["번호" + cnt].Value = cnt; sheetView.Cells["품명" + cnt].Value = dataRow["품명"].ToString(); sheetView.Cells["사양" + cnt].Value = dataRow["규격"].ToString(); } }
private void SetActiveCell(FarPoint.Win.Spread.FpSpread spread, FarPoint.Win.Spread.SheetView sheet, int row, int column) { if (sheet.RowCount == 0 || sheet.Cells[row, column] == null) { return; } if (sheet.ActiveRow != null) { sheet.ActiveRow.BackColor = Color.White; } sheet.Rows[row].BackColor = Constants.Constants.ACTIVE_COLOR; sheet.SetActiveCell(row, column); spread.ShowActiveCell(VerticalPosition.Nearest, HorizontalPosition.Nearest); }
/// <summary> /// 현재 시트에 선택된 row의 datarowview를 리턴한다. /// </summary> /// <param name="sv"></param> /// <returns></returns> public static DataRowView SelectRow_DataRowView_Get(FarPoint.Win.Spread.SheetView sv) { if (sv.DataSource == null) { return(null); } int intRow = sv.ActiveRowIndex; if (intRow < 0) { return(null); } return(((DataView)sv.DataSource)[intRow]); }
/// <summary> /// row를 삭제 한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="intDelIndex">삭제 위치 : '-1'이면 마지막부터 위로 삭제 시킨다.</param> /// <param name="intDelRowCount"></param> public static void Invoke_DeleteRow(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int intDelIndex, int intDelRowCount) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_AddRow(Invoke_DeleteRow), new object[] { fp, sv, intDelIndex, intDelRowCount }); return; } if (intDelIndex < 0) { intDelIndex = sv.Rows.Count - intDelRowCount; } sv.Rows.Remove(intDelIndex, intDelRowCount); }
public int AddItem(FarPoint.Win.Spread.SheetView sv, int activeRow) { string drugNO = sv.Cells[activeRow, 0].Text; string batchNO = sv.Cells[activeRow, 3].Text; decimal storeQty = 0; this.itemManager.GetStorageNum(this.phaOutManager.DeptInfo.ID, drugNO, out storeQty); if (this.AddDrugData(drugNO, batchNO, storeQty) == 1) { this.SetFormat(); this.SetFocusSelect(); } return(1); }
//********************************************************************** /// <summary> /// SheetView→CSV出力文字変換 /// </summary> /// <param name="Sheet1">アクティブなシート</param> /// <param name="st_row">出力開始行</param> /// <param name="st_colum">出力開始列</param> /// <param name="end_row">出力終了行</param> /// <param name="end_colum">出力終了列</param> /// <returns>CSV出力文字</returns> //********************************************************************** public static string SheetViewToCsv(FarPoint.Win.Spread.SheetView Sheet1, int st_row, int st_colum, int end_row, int end_colum) { try { //明細を連結 System.IO.MemoryStream st = new System.IO.MemoryStream(); Sheet1.SaveTextFileRange(st_row, st_colum, end_row, end_colum, st, true, IncludeHeaders.ColumnHeadersCustomOnly, Environment.NewLine, ",", ""); string detailData = Encoding.GetEncoding("shift_jis").GetString(st.ToArray()); return(detailData); } catch (Exception ex) { return(string.Empty); } }
/// <summary> /// 셀에 값을 변경한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="Y"></param> /// <param name="X"></param> /// <param name="objValue"></param> public static void Invoke_Cell_Value(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int Y, int X, object objValue) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_Cell_Value(Invoke_Cell_Value), new object[] { fp, sv, Y, X, objValue }); return; } try { sv.Cells[Y, X].Value = objValue; } catch (Exception ex) { log.WLog_Exception(string.Format("{0}[sv]{1}[y}{2}[x]{3][obj]{4}", "Invoke_Cell_Value", fp.Name, Y, X, objValue), ex); } }
private void Show보전이력Data(DataTable datatable) { FarPoint.Win.Spread.SheetView sheetView = fpSpread설비이력.ActiveSheet; int cnt = 0; foreach (DataRow dataRow in datatable.Rows) { cnt++; sheetView.Cells["보전번호" + cnt].Value = cnt; sheetView.Cells["일자" + cnt].Value = Convert.ToDateTime(dataRow["수리일자"]).ToString("yyyy-MM-dd"); sheetView.Cells["고장내용" + cnt].Value = dataRow["고장내용"].ToString(); sheetView.Cells["수리점검내용" + cnt].Value = dataRow["수리내역"].ToString(); sheetView.Cells["수리부품" + cnt].Value = dataRow["수리부품"].ToString(); sheetView.Cells["수리처구매처" + cnt].Value = dataRow["수리처"].ToString(); sheetView.Cells["비용" + cnt].Value = dataRow["비용"]; sheetView.Cells["시간" + cnt].Value = dataRow["시간"]; } }
public int Delete(FarPoint.Win.Spread.SheetView sv, int delRowIndex) { try { if (sv != null && delRowIndex >= 0) { DialogResult rs = MessageBox.Show(Language.Msg("确认删除该条数据吗?"), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (rs == DialogResult.No) { return(0); } string[] keys = new string[] { sv.Cells[delRowIndex, (int)ColumnSet.ColDrugNO].Text, sv.Cells[delRowIndex, (int)ColumnSet.ColBatchNO].Text }; DataRow dr = this.dt.Rows.Find(keys); if (dr != null) { this.phaOutManager.Fp.StopCellEditing(); this.hsOutData.Remove(dr["药品编码"].ToString() + dr["批号"].ToString()); this.dt.Rows.Remove(dr); this.phaOutManager.Fp.StartCellEditing(null, false); } } } catch (System.Data.DataException e) { System.Windows.Forms.MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("对数据表执行删除操作发生错误" + e.Message)); return(-1); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("对数据表执行删除操作发生错误" + ex.Message)); return(-1); } return(1); }
/// <summary> /// 设置cell下来列表 /// </summary> /// <param name="view"></param> /// <param name="col"></param> /// <param name="al"></param> public void SetColumnList(FarPoint.Win.Spread.SheetView view, int col, ArrayList al) { string name = view.SheetName + "_" + col.ToString(); for (int i = 0; i < this.Lists.Length - 1; i++) { if (this.Lists[i] != null && (this.Lists[i] as Neusoft.FrameWork.WinForms.Controls.NeuListBoxPopup).Name == name) { return; } } Neusoft.FrameWork.WinForms.Controls.NeuListBoxPopup obj = new Neusoft.FrameWork.WinForms.Controls.NeuListBoxPopup(); obj.Name = name; obj.AddItems(al); //得到最大列表数 int Index = -1; for (int i = 0; i < this.Lists.Length; i++) { if (this.Lists[i] == null) { Index = i; break; } } if (Index == -1) { MessageBox.Show("列表已经超过最大数10", "提示"); return; } this.Lists[Index] = obj; this.Lists[Index].ItemSelected += new EventHandler(FpEnter_ItemSelected); //this.Lists[Index].ItemSelected += new Neusoft.FrameWork.WinForms.Controls.NeuListBoxPopup(FpEnter_SelectItem); this.Controls.Add(this.Lists[Index]); this.Lists[Index].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.Lists[Index].Cursor = Cursors.Hand; this.Lists[Index].Size = new System.Drawing.Size(intWidth, intHeight); this.Lists[Index].Visible = false; //this.Lists[Index].SelectNone = selectNone; }
/// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// </summary> private void InitializeComponent() { this.fpSpread1 = new FarPoint.Win.Spread.FpSpread(); this.fpSpread1_Sheet1 = new FarPoint.Win.Spread.SheetView(); ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.fpSpread1_Sheet1)).BeginInit(); this.SuspendLayout(); // // fpSpread1 // this.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill; this.fpSpread1.EditModePermanent = true; this.fpSpread1.EditModeReplace = true; this.fpSpread1.Location = new System.Drawing.Point(0, 0); this.fpSpread1.Name = "fpSpread1"; this.fpSpread1.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] { this.fpSpread1_Sheet1 }); this.fpSpread1.Size = new System.Drawing.Size(536, 360); this.fpSpread1.TabIndex = 0; this.fpSpread1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.fpSpread1_KeyPress); this.fpSpread1.EditModeOn += new System.EventHandler(this.fpSpread1_EditModeOn); this.fpSpread1.EditModeOff += new System.EventHandler(this.fpSpread1_EditModeOff); this.fpSpread1.ComboSelChange += new FarPoint.Win.Spread.EditorNotifyEventHandler(this.fpSpread1_ComboSelChange); this.fpSpread1.Change += new FarPoint.Win.Spread.ChangeEventHandler(this.fpSpread1_Change); this.fpSpread1.EditChange += new FarPoint.Win.Spread.EditorNotifyEventHandler(this.fpSpread1_EditChange); // // fpSpread1_Sheet1 // this.fpSpread1_Sheet1.Reset(); this.fpSpread1_Sheet1.SheetName = "Sheet1"; // // fpInput // this.Controls.Add(this.fpSpread1); this.Name = "fpInput"; this.Size = new System.Drawing.Size(536, 360); this.Load += new System.EventHandler(this.fpInput_Load); ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.fpSpread1_Sheet1)).EndInit(); this.ResumeLayout(false); }
/// <summary> /// databinding with field /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="dt"></param> /// <param name="strField"></param> public static void Invoke_DataSource(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, DataView dt, string[] strField, StBindingOption bindingOption) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_DataSource2(Invoke_DataSource), new object[] { fp, sv, dt, strField, bindingOption }); return; } try { sv.AutoGenerateColumns = bindingOption.AutoGenerateColumns; sv.DataAutoHeadings = bindingOption.DataAutoHeadings; sv.DataAutoCellTypes = bindingOption.DataAutoCellTypes; sv.DataAutoSizeColumns = bindingOption.DataAutoSizeColumns; sv.Rows.Count = 0; if (dt != null) { sv.DataSource = dt; } if (strField == null) { return; } for (int x = 0; x < strField.Length; x++) { sv.Columns[x].DataField = strField[x]; } } catch (Exception ex) { log.WLog_Exception(string.Format("{0}[fp]{1}", "Invoke_DataSource", fp.Name), ex); } }
//重写了框架的颜色方法,原来的框架在解锁方面有点问题,不方便在框架直接修改,所以重新写了一个 public void Gp_Sp_BlockColor(FpSpread oSpread, int iCol1, int iCol2, int iRow1, int iRow2, Color fColor, Color bColor) { FarPoint.Win.Spread.SheetView with_1 = oSpread.ActiveSheet; for (int row = iRow1; row <= iRow2; row++) { for (int col = iCol1; col <= iCol2; col++) { bool locked = with_1.Columns[col].Locked; with_1.Columns[col].Locked = false; with_1.Cells[row, col].Locked = false; //我在这里加了一个颜色的判断,防止多个颜色的时候,颜色覆盖替换的问题,所以在赋值的时候,黑色字体和白色背景不会被传入进行修改 if (fColor != Color.Black) { with_1.Cells[row, col].ForeColor = fColor; } if (bColor != Color.White) { with_1.Cells[row, col].BackColor = bColor; } with_1.Cells[row, col].Locked = locked; with_1.Columns[col].Locked = locked; } } }
private void Show설비Data(DataTable datatable) { if (datatable.Rows.Count == 0) { MessageBox.Show("저장한 정보만 인쇄가 가능합니다. 저장 후에 다시 시도해주세요.", "저장하지 않은 정보 인쇄 오류", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FarPoint.Win.Spread.SheetView sheetView = fpSpread설비이력.ActiveSheet; DataRow dataRow = datatable.Rows[0]; sheetView.Cells["관리번호"].Value = dataRow["관리코드"].ToString(); sheetView.Cells["설비명"].Value = dataRow["품명"].ToString(); sheetView.Cells["형식또는규격"].Value = dataRow["규격"].ToString(); sheetView.Cells["제조회사"].Value = dataRow["제조회사"].ToString(); sheetView.Cells["구입일자"].Value = Convert.ToDateTime(dataRow["구입일자"]).ToString("yyyy-MM-dd"); sheetView.Cells["구입금액"].Value = Convert.ToInt32(dataRow["금액"]); sheetView.Cells["설치장소"].Value = dataRow["설치장소"].ToString(); sheetView.Cells["등급"].Value = " " + dataRow["등급"].ToString(); sheetView.Cells["관리자"].Value = dataRow["관리책임자"].ToString() + " "; if (dataRow["사진"] != vs) { sheetView.Cells["사진및약도"].Value = (byte[])dataRow["사진"]; } }
/// <summary> /// 해당 Row의 forecolor과 backcolor을 변경한다. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="intRow"></param> /// <param name="colFore">null 이면 변경 않</param> /// <param name="colBack">null 이면 변경 않</param> public static void Invoke_Row_SetColor(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int intRow, object colFore, object colBack) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_Row_SetColor(Invoke_Row_SetColor), new object[] { fp, sv, intRow, colFore, colBack }); return; } if (intRow >= sv.RowCount) { return; } if (colBack != null) { sv.Rows[intRow].BackColor = (Color)colBack; } if (colFore != null) { sv.Rows[intRow].ForeColor = (Color)colFore; } fp.Refresh(); }
protected virtual void Export() { if (this.bTabControl1.SelectedIndex == 0) { //this.bsprData.Export(false); string file = ""; bool bProtect = this.bsprData.ActiveSheet.Protect; this.bsprData.ActiveSheet.Protect = false; SaveFileDialog openDlg = new SaveFileDialog(); openDlg.Filter = "Excel Files (*.xls)|*.xls"; openDlg.FileName = ""; openDlg.DefaultExt = ".xls"; openDlg.CheckFileExists = false; openDlg.CheckPathExists = true; DialogResult res = openDlg.ShowDialog(); if (res != DialogResult.OK) { return; } file = openDlg.FileName; FarPoint.Win.Spread.SheetView spread_Sheet1 = new FarPoint.Win.Spread.SheetView(); spread_Sheet1.SheetName = "_ExcelExportSheet"; FarPoint.Win.Spread.FpSpread spread = new FarPoint.Win.Spread.FpSpread(); spread.Sheets.Add(spread_Sheet1); spread_Sheet1.Visible = true; spread.ActiveSheet = spread_Sheet1; byte[] buffer = null; System.IO.MemoryStream stream = null; this.bsprData.SetFilterVisible(false); try { stream = new System.IO.MemoryStream(); this.bsprData.Save(stream, false); buffer = stream.ToArray(); stream.Close(); } catch (Exception ex) { throw ex; } finally { if (stream != null) { stream.Dispose(); stream = null; } } stream = new System.IO.MemoryStream(buffer); spread.Open(stream); if (stream != null) { stream.Dispose(); stream = null; } for (int i = spread.ActiveSheet.Columns.Count - 1; i >= 0; i--) { if (!spread.ActiveSheet.Columns[i].Visible) { spread.ActiveSheet.Columns[i].Remove(); } } spread.SaveExcel(file, FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly); this.bsprData.ActiveSheet.Protect = bProtect; string strMessage = "It was saved successfully. Do you open saved file?"; DialogResult result = MessageBox.Show(strMessage, "Open", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\Applications\EXCEL.EXE"); if (key == null) { MSGHandler.DisplayMessage(MSGType.Error, "SPC_INFO_NEED_MS_OFFICE", null, null); } else { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = file; process.Start(); } } } else { string file = ""; bool bProtect = this.bsprRawData.ActiveSheet.Protect; this.bsprRawData.ActiveSheet.Protect = false; SaveFileDialog openDlg = new SaveFileDialog(); openDlg.Filter = "Excel Files (*.xls)|*.xls"; openDlg.FileName = ""; openDlg.DefaultExt = ".xls"; openDlg.CheckFileExists = false; openDlg.CheckPathExists = true; DialogResult res = openDlg.ShowDialog(); if (res != DialogResult.OK) { return; } file = openDlg.FileName; FarPoint.Win.Spread.SheetView spread_Sheet1 = new FarPoint.Win.Spread.SheetView(); spread_Sheet1.SheetName = "_ExcelExportSheet"; FarPoint.Win.Spread.FpSpread spread = new FarPoint.Win.Spread.FpSpread(); spread.Sheets.Add(spread_Sheet1); spread_Sheet1.Visible = true; spread.ActiveSheet = spread_Sheet1; byte[] buffer = null; System.IO.MemoryStream stream = null; this.bsprRawData.SetFilterVisible(false); try { stream = new System.IO.MemoryStream(); this.bsprRawData.Save(stream, false); buffer = stream.ToArray(); stream.Close(); } catch (Exception ex) { throw ex; } finally { if (stream != null) { stream.Dispose(); stream = null; } } stream = new System.IO.MemoryStream(buffer); spread.Open(stream); if (stream != null) { stream.Dispose(); stream = null; } for (int i = spread.ActiveSheet.Columns.Count - 1; i >= 0; i--) { if (!spread.ActiveSheet.Columns[i].Visible) { spread.ActiveSheet.Columns[i].Remove(); } } spread.SaveExcel(file, FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly); this.bsprRawData.ActiveSheet.Protect = bProtect; string strMessage = "It was saved successfully. Do you open saved file?"; DialogResult result = MessageBox.Show(strMessage, "Open", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\Applications\EXCEL.EXE"); if (key == null) { MSGHandler.DisplayMessage(MSGType.Error, "SPC_INFO_NEED_MS_OFFICE", null, null); } else { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = file; process.Start(); } } } }
/// <summary> /// 범위에 ForeColor와 BackColor를 변경하여 준다.. /// </summary> /// <param name="fp"></param> /// <param name="sv"></param> /// <param name="intStRow">시작 row</param> /// <param name="intEdRow">종료 row</param> /// <param name="intStCol">시작 col</param> /// <param name="intEdCol">종료 col</param> /// <param name="colFore">object color - 변경 안할시에는 null</param> /// <param name="colBack">object color - 변경 안할시에는 null</param> public static void Invoke_CellRange_SetRowColor(FarPoint.Win.Spread.FpSpread fp, FarPoint.Win.Spread.SheetView sv, int intStRow, int intEdRow, int intStCol, int intEdCol, object colFore, object colBack) { if (fp.InvokeRequired) { fp.Invoke(new delInvoke_CellRange_SetRowColor(Invoke_CellRange_SetRowColor), new object[] { fp, sv, intStRow, intEdRow, intStCol, intEdCol, colFore, colBack }); return; } if (colFore != null) { sv.Cells[intStRow, intStCol, intEdRow, intEdCol].ForeColor = (Color)colFore; } if (colBack != null) { sv.Cells[intStRow, intStCol, intEdRow, intEdCol].BackColor = (Color)colBack; } fp.Refresh(); }