internal SLDefinedName Clone() { SLDefinedName dn = new SLDefinedName(this.Name); dn.Text = this.Text; dn.Name = this.Name; dn.Comment = this.Comment; dn.CustomMenu = this.CustomMenu; dn.Description = this.Description; dn.Help = this.Help; dn.StatusBar = this.StatusBar; dn.LocalSheetId = this.LocalSheetId; dn.Hidden = this.Hidden; dn.Function = this.Function; dn.VbProcedure = this.VbProcedure; dn.Xlm = this.Xlm; dn.FunctionGroupId = this.FunctionGroupId; dn.ShortcutKey = this.ShortcutKey; dn.PublishToServer = this.PublishToServer; dn.WorkbookParameter = this.WorkbookParameter; return(dn); }
private void SetAddPrintArea(int StartRowIndex, int StartColumnIndex, int EndRowIndex, int EndColumnIndex, bool ToAdd) { if (StartRowIndex < 1) { StartRowIndex = 1; } if (StartRowIndex > SLConstants.RowLimit) { StartRowIndex = SLConstants.RowLimit; } if (StartColumnIndex < 1) { StartColumnIndex = 1; } if (StartColumnIndex > SLConstants.ColumnLimit) { StartColumnIndex = SLConstants.ColumnLimit; } if (EndRowIndex < 1) { EndRowIndex = 1; } if (EndRowIndex > SLConstants.RowLimit) { EndRowIndex = SLConstants.RowLimit; } if (EndColumnIndex < 1) { EndColumnIndex = 1; } if (EndColumnIndex > SLConstants.ColumnLimit) { EndColumnIndex = SLConstants.ColumnLimit; } // no overlapping checked. int iSheetPosition = 0; int i; for (i = 0; i < slwb.Sheets.Count; ++i) { if (slwb.Sheets[i].Name.Equals(gsSelectedWorksheetName, StringComparison.OrdinalIgnoreCase)) { iSheetPosition = i; break; } } string sPrintArea = string.Empty; if (StartRowIndex == EndRowIndex && StartColumnIndex == EndColumnIndex) { // why would you print just one cell? Even Excel questions this with a message box... sPrintArea = SLTool.ToCellReference(gsSelectedWorksheetName, StartRowIndex, StartColumnIndex, true); } else { sPrintArea = SLTool.ToCellRange(gsSelectedWorksheetName, StartRowIndex, StartColumnIndex, EndRowIndex, EndColumnIndex, true); } bool bFound = false; for (i = 0; i < slwb.DefinedNames.Count; ++i) { if (slwb.DefinedNames[i].Name.Equals(SLConstants.PrintAreaDefinedName, StringComparison.OrdinalIgnoreCase) && slwb.DefinedNames[i].LocalSheetId != null && slwb.DefinedNames[i].LocalSheetId.Value == iSheetPosition) { bFound = true; if (ToAdd) { slwb.DefinedNames[i].Text = string.Format("{0},{1}", slwb.DefinedNames[i].Text, sPrintArea); } else { slwb.DefinedNames[i].Text = sPrintArea; } } } if (!bFound) { SLDefinedName dn = new SLDefinedName(SLConstants.PrintAreaDefinedName); dn.LocalSheetId = (uint)iSheetPosition; dn.Text = sPrintArea; slwb.DefinedNames.Add(dn); } }
/// <summary> /// Set a given defined name. If it doesn't exist, a new defined name is created. If it exists, then the existing defined name is overwritten. /// </summary> /// <param name="Name">Name of defined name. Note that it cannot be a valid cell reference such as A1. It also cannot start with "_xlnm" because it's reserved.</param> /// <param name="Text">The reference/content text of the defined name. For example, Sheet1!$A$1:$C$3</param> /// <param name="Comment">Comment for the defined name.</param> /// <param name="Scope">The name of the worksheet that the defined name is effective in.</param> /// <returns>True if the given defined name is created or an existing defined name is overwritten. False otherwise.</returns> public bool SetDefinedName(string Name, string Text, string Comment, string Scope) { Name = Name.Trim(); if (SLTool.IsCellReference(Name)) { return(false); } // these are reserved names if (Name.StartsWith("_xlnm")) { return(false); } if (Text.StartsWith("=")) { if (Text.Length > 1) { Text = Text.Substring(1); } else { Text = "\"=\""; } } uint?iLocalSheetId = null; for (int i = 0; i < slwb.Sheets.Count; ++i) { if (slwb.Sheets[i].Name.Equals(Scope, StringComparison.OrdinalIgnoreCase)) { iLocalSheetId = (uint)i; break; } } bool bFound = false; SLDefinedName dn = new SLDefinedName(Name); dn.Text = Text; if (Comment != null && Comment.Length > 0) { dn.Comment = Comment; } if (iLocalSheetId != null) { dn.LocalSheetId = iLocalSheetId.Value; } foreach (SLDefinedName d in slwb.DefinedNames) { if (d.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)) { bFound = true; d.Text = Text; if (Comment != null && Comment.Length > 0) { d.Comment = Comment; } break; } } if (!bFound) { slwb.DefinedNames.Add(dn); } return(true); }