本文整理汇总了C#中Microsoft.Office.Interop.Excel.Worksheet.Protect方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.Protect方法的具体用法?C# Worksheet.Protect怎么用?C# Worksheet.Protect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.Worksheet
的用法示例。
在下文中一共展示了Worksheet.Protect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handleCommon
//.........这里部分代码省略.........
if (definition.Contains("<def-source>"))
{
XElement e = XElement.Parse("<def>" + definition + "</def>");
definition = e.Element("def-definition").Value + "\n(Source: " + e.Element("def-source").Value + ")";
}
}
string attr = createAttrs(selectedNode, name);
string label = id + ":" + preferredName;
string[] concepts = null;
Excel.Range selected = (Excel.Range)application.Selection;
string hLinkLabel = "";
if (annotate && (!name.Equals("vd") && !name.Equals("dec") && !name.Equals("cd")))
{
concepts = extractConcepts(attr).Split(';');
Excel.Range leftCell = selected.get_Offset(0, -1);
string prim = concepts[concepts.Length - 1];
string quals = "";
for (int i = 0; i < concepts.Length - 1; i++)
quals += concepts[i] + ";";
if (quals.Length > 0)
quals = quals.Substring(0, quals.Length - 1);
if ((selected.Value2 == null || selected.Value2.ToString().Length == 0) && (((leftCell.Value2 == null || leftCell.Value2.ToString().Length == 0) || quals.Length == 0)))
{
selected.Value2 = prim;
hLinkLabel = prim;
if (quals.Length > 0)
leftCell.Value2 = quals;
}
}
else
{
//Get selected range
if (selected.Value2 == null || selected.Value2.ToString().Length == 0)
{
selected.Value2 = label;
hLinkLabel = label;
}
else
{
//Refuse to add? Do you have to remove first?
}
}
// empty hlink indicates non-empty cell. don't overwrite
if (hLinkLabel.Length > 0)
{
//Create concept list if not exists
propList = useList(propList, name + "_list");
//Add new concept entry to concept_list
propList.Unprotect(dummyPass);
Excel.Range c = (Excel.Range)propList.Cells[2, 1];
Excel.Range found = propList.Cells.Find(id, Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing);
if (found == null) //if (existingIndex == 0)
{
for (int i = 3; c.Value2 != null; i++)
{
c = (Excel.Range)propList.Cells[i, 1];
}
c.Value2 = fullId;
c.Next.Value2 = preferredName;
c.Next.Next.Value2 = definition.Trim().Replace(">", ">").Replace("<", "<").Replace("&", "&");
c.Next.Next.Next.Value2 = attr.Trim().Replace(",", "\n\n").Replace(",", ", ").Replace(">", ">").Replace("<", "<").Replace("&", "&");
//Cells mapped counter
//c.Next.Next.Next.Next.Value2 = 1;
}
else
{
found.Next.Next.Next.Next.Value2 = 1 + Convert.ToInt16(found.Next.Next.Next.Next.Value2.ToString());
}
propList.Protect(dummyPass, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
/* Remove hyperlinks for now until a suitable two way link method is found */
//Do not overwrite if something is in there already
selected.Hyperlinks.Add(selected, "", getSelectedRangeAddress(c), Type.Missing, hLinkLabel);
selected.Font.Bold = true;
selected.Font.Underline = false;
if (annotate)
annotateComment(selected);
else
{
selected.Font.ColorIndex = 1;
selected.Interior.ThemeColor = Excel.XlThemeColor.xlThemeColorAccent3;
selected.Interior.TintAndShade = 0.2;
}
}
}
示例2: handleProp
protected void handleProp(QueryServiceControl.QueryServiceManager.property property)
{
string id = property.names.id;
//Removing the institution identifying prefix from CADSR elements on client request
if (id.Contains("-CADSR-"))
{
string[] idarr = id.Split('-');
id = idarr[idarr.Length - 2] + " v." + idarr[idarr.Length - 1];
}
string preferredName = property.names.preferred;
string definition = QueryServiceControl.QueryServiceControl.getDefinition(property.definition);
string label = preferredName;
//Get selected range
Excel.Range selected = (Excel.Range)application.Selection;
if (selected.Value2 == null || selected.Value2.ToString().Length == 0)
{
selected.Value2 = label;
}
else
{
//Refuse to add? Do you have to remove first?
}
//Create concept list if not exists
propList = useList(propList, "prop_list");
//Add new concept entry to concept_list
propList.Unprotect(dummyPass);
Excel.Range c = (Excel.Range)propList.Cells[2, 1];
Excel.Range found = propList.Cells.Find(id, Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing);
if (found == null) //if (existingIndex == 0)
{
for (int i = 3; c.Value2 != null; i++)
{
c = (Excel.Range)ocList.Cells[i, 1];
}
c.Value2 = id;
c.Next.Value2 = preferredName;
c.Next.Next.Value2 = definition.Trim().Replace(">", ">").Replace("<", "<").Replace("&", "&");
//c.Next.Next.Next.Value2 = attr.Trim().Replace(",", "\n\n").Replace(",", ", ").Replace(">", ">").Replace("<", "<").Replace("&", "&");
//Cells mapped counter
c.Next.Next.Next.Next.Value2 = 1;
}
else
{
found.Next.Next.Next.Next.Value2 = 1 + Convert.ToInt16(found.Next.Next.Next.Next.Value2.ToString());
}
propList.Protect(dummyPass, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
/* Remove hyperlinks for now until a suitable two way link method is found */
selected.Hyperlinks.Add(selected, "", getSelectedRangeAddress(c), Type.Missing, label);
selected.Font.Bold = true;
selected.Font.Underline = false;
selected.Font.ColorIndex = 1;
selected.Interior.ThemeColor = Excel.XlThemeColor.xlThemeColorAccent3;
selected.Interior.TintAndShade = 0.2;
}
示例3: createConceptList
private void createConceptList()
{
Excel.Worksheet origin = (Excel.Worksheet)application.ActiveSheet;
conceptList = (Excel.Worksheet)application.ActiveWorkbook.Worksheets.Add(Type.Missing, application.ActiveSheet, Type.Missing, Type.Missing);
conceptList.Name = "concept_list";
Excel.Range column = ((Excel.Range)conceptList.Cells[1, 1]);
//ID
column.Value2 = "ID";
column.Font.Bold = true;
column.Font.Background = Excel.XlBackground.xlBackgroundOpaque;
column.EntireColumn.ColumnWidth = 25;
column.EntireColumn.WrapText = true;
column.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
//Name
column.Next.Value2 = "Name";
column.Next.Font.Bold = true;
column.Next.Font.Background = Excel.XlBackground.xlBackgroundOpaque;
column.Next.EntireColumn.ColumnWidth = 30;
column.Next.EntireColumn.WrapText = true;
column.Next.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
//Definition
column.Next.Next.Value2 = "Definition";
column.Next.Next.Font.Bold = true;
column.Next.Next.Font.Background = Excel.XlBackground.xlBackgroundOpaque;
column.Next.Next.EntireColumn.ColumnWidth = 60;
column.Next.Next.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
column.Next.Next.EntireColumn.WrapText = true;
column.Next.Next.EntireColumn.HorizontalAlignment = Excel.XlHAlign.xlHAlignJustify;
//Source
column.Next.Next.Next.Value2 = "Source";
column.Next.Next.Next.Font.Bold = true;
column.Next.Next.Next.Font.Background = Excel.XlBackground.xlBackgroundOpaque;
column.Next.Next.Next.EntireColumn.ColumnWidth = 30;
column.Next.Next.Next.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
column.Next.Next.Next.EntireColumn.WrapText = true;
column.Next.Next.Next.EntireColumn.HorizontalAlignment = Excel.XlHAlign.xlHAlignJustify;
//Definition
column.Next.Next.Next.Next.Value2 = "Mapped Cells";
column.Next.Next.Next.Next.Font.Bold = true;
column.Next.Next.Next.Next.Font.Background = Excel.XlBackground.xlBackgroundOpaque;
column.Next.Next.Next.Next.EntireColumn.ColumnWidth = 60;
column.Next.Next.Next.Next.EntireColumn.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
column.Next.Next.Next.Next.EntireColumn.WrapText = true;
column.Next.Next.Next.Next.EntireColumn.HorizontalAlignment = Excel.XlHAlign.xlHAlignJustify;
conceptList.Protect(dummyPass, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//((Excel.Worksheet)application.Worksheets.get_Item(origin.Name)).Activate();
(origin as Microsoft.Office.Interop.Excel._Worksheet).Activate();
}
示例4: handleProp
protected void handleProp(XElement selectedNode)
{
string id = selectedNode.Element(rs + "names").Element(rs + "id").Value;
//Removing the institution identifying prefix from CADSR elements on client request
if (id.Contains("-CADSR-"))
{
string[] idarr = id.Split('-');
id = idarr[idarr.Length - 2] + " v." + idarr[idarr.Length - 1];
}
string preferredName = selectedNode.Element(rs + "names").Element(rs + "preferred").Value;
string definition = selectedNode.Element(rs + "definition").Value;
if (definition == null || definition.Length == 0)
{
definition = "(No definition supplied)";
}
else
{
//Handle special caDSR/EVS format
definition = definition.Trim().Replace(">", ">").Replace("<", "<").Replace("<![CDATA[", "").Replace("]]>", "");
if (definition.Contains("<def-source>"))
{
XElement e = XElement.Parse("<def>" + definition + "</def>");
definition = e.Element("def-definition").Value + "\n(Source: " + e.Element("def-source").Value + ")";
}
}
string label = preferredName;
//Get selected range
Excel.Range selected = (Excel.Range)application.Selection;
if (selected.Value2 == null || selected.Value2.ToString().Length == 0)
{
selected.Value2 = label;
}
else
{
//Refuse to add? Do you have to remove first?
}
//Create concept list if not exists
propList = useList(propList, "prop_list");
//Add new concept entry to concept_list
propList.Unprotect(dummyPass);
Excel.Range c = (Excel.Range)propList.Cells[2, 1];
Excel.Range found = propList.Cells.Find(id, Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing);
if (found == null) //if (existingIndex == 0)
{
for (int i = 3; c.Value2 != null; i++)
{
c = (Excel.Range)ocList.Cells[i, 1];
}
c.Value2 = id;
c.Next.Value2 = preferredName;
c.Next.Next.Value2 = definition.Trim().Replace(">", ">").Replace("<", "<").Replace("&", "&");
//c.Next.Next.Next.Value2 = attr.Trim().Replace(",", "\n\n").Replace(",", ", ").Replace(">", ">").Replace("<", "<").Replace("&", "&");
//Cells mapped counter
c.Next.Next.Next.Next.Value2 = 1;
}
else
{
found.Next.Next.Next.Next.Value2 = 1 + Convert.ToInt16(found.Next.Next.Next.Next.Value2.ToString());
}
propList.Protect(dummyPass, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
/* Remove hyperlinks for now until a suitable two way link method is found */
selected.Hyperlinks.Add(selected, "", getSelectedRangeAddress(c), Type.Missing, label);
selected.Font.Bold = true;
selected.Font.Underline = false;
selected.Font.ColorIndex = 1;
selected.Interior.ThemeColor = Excel.XlThemeColor.xlThemeColorAccent3;
selected.Interior.TintAndShade = 0.2;
}