c# - 在当前上下文中不存在 c#

标签 c# visual-studio-2013

从一个销售能够处理 excel 文件的组件的网站的示例部分得到这个

我将其复制粘贴到 visual studio 2013 中,但我一直收到此错误...

“颜色”在当前上下文中不存在...

我一直在网上阅读有关这些错误的信息,但有些人给出了解决方案,但没有 关于“为什么”存在此错误的关键答案

关于在方法内部或外部声明变量的一些事情,就像这个网站上的许多人一样,我正在冒险 newb 的路径

谢谢你的帮助

链接在这里是你感兴趣的

http://www.gemboxsoftware.com/SampleExplorer/Spreadsheet/BasicFeatures/StylesandFormatting?tab=cs

using System;
using System.Drawing;
using System.IO;
using GemBox.Spreadsheet;

class Sample
{
[STAThread]
static void Main(string[] args)
{
    // If using Professional version, put your serial key below.
    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

    ExcelFile ef = new ExcelFile();
    ExcelWorksheet ws = ef.Worksheets.Add("Styles and Formatting");

    ws.Cells[0, 1].Value = "Cell style examples:";
    ws.PrintOptions.PrintGridlines = true;

    int row = 0;

    // Column width of 4, 30 and 35 characters.
    ws.Columns[0].Width = 4 * 256;
    ws.Columns[1].Width = 30 * 256;
    ws.Columns[2].Width = 35 * 256;

    ws.Cells[row += 2, 1].Value = ".Style.Borders.SetBorders(...)";
    ws.Cells[row, 2].Style.Borders.SetBorders(MultipleBorders.All, Color.FromArgb(252, 1, 1), LineStyle.Thin);

    ws.Cells[row += 2, 1].Value = ".Style.FillPattern.SetPattern(...)";
    ws.Cells[row, 2].Style.FillPattern.SetPattern(FillPatternStyle.ThinHorizontalCrosshatch, Color.Green, Color.Yellow);

    ws.Cells[row += 2, 1].Value = ".Style.Font.Color =";
    ws.Cells[row, 2].Value = "Color.Blue";
    ws.Cells[row, 2].Style.Font.Color = Color.Blue;

    ws.Cells[row += 2, 1].Value = ".Style.Font.Italic =";
    ws.Cells[row, 2].Value = "true";
    ws.Cells[row, 2].Style.Font.Italic = true;

    ws.Cells[row += 2, 1].Value = ".Style.Font.Name =";
    ws.Cells[row, 2].Value = "Comic Sans MS";
    ws.Cells[row, 2].Style.Font.Name = "Comic Sans MS";

    ws.Cells[row += 2, 1].Value = ".Style.Font.ScriptPosition =";
    ws.Cells[row, 2].Value = "ScriptPosition.Superscript";
    ws.Cells[row, 2].Style.Font.ScriptPosition = ScriptPosition.Superscript;

    ws.Cells[row += 2, 1].Value = ".Style.Font.Size =";
    ws.Cells[row, 2].Value = "18 * 20";
    ws.Cells[row, 2].Style.Font.Size = 18 * 20;

    ws.Cells[row += 2, 1].Value = ".Style.Font.Strikeout =";
    ws.Cells[row, 2].Value = "true";
    ws.Cells[row, 2].Style.Font.Strikeout = true;

    ws.Cells[row += 2, 1].Value = ".Style.Font.UnderlineStyle =";
    ws.Cells[row, 2].Value = "UnderlineStyle.Double";
    ws.Cells[row, 2].Style.Font.UnderlineStyle = UnderlineStyle.Double;

    ws.Cells[row += 2, 1].Value = ".Style.Font.Weight =";
    ws.Cells[row, 2].Value = "ExcelFont.BoldWeight";
    ws.Cells[row, 2].Style.Font.Weight = ExcelFont.BoldWeight;

    ws.Cells[row += 2, 1].Value = ".Style.HorizontalAlignment =";
    ws.Cells[row, 2].Value = "HorizontalAlignmentStyle.Center";
    ws.Cells[row, 2].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;

    ws.Cells[row += 2, 1].Value = ".Style.Indent";
    ws.Cells[row, 2].Value = "five";
    ws.Cells[row, 2].Style.HorizontalAlignment = HorizontalAlignmentStyle.Left;
    ws.Cells[row, 2].Style.Indent = 5;

    ws.Cells[row += 2, 1].Value = ".Style.IsTextVertical = ";
    ws.Cells[row, 2].Value = "true";
    // Set row height to 50 points.
    ws.Rows[row].Height = 50 * 20;
    ws.Cells[row, 2].Style.IsTextVertical = true;

    ws.Cells[row += 2, 1].Value = ".Style.NumberFormat";
    ws.Cells[row, 2].Value = 1234;
    ws.Cells[row, 2].Style.NumberFormat = "#.##0,00 [$Krakozhian Money Units]";

    ws.Cells[row += 2, 1].Value = ".Style.Rotation";
    ws.Cells[row, 2].Value = "35 degrees up";
    ws.Cells[row, 2].Style.Rotation = 35;

    ws.Cells[row += 2, 1].Value = ".Style.ShrinkToFit";
    ws.Cells[row, 2].Value = "This property is set to true so this text appears shrunk.";
    ws.Cells[row, 2].Style.ShrinkToFit = true;

    ws.Cells[row += 2, 1].Value = ".Style.VerticalAlignment =";
    ws.Cells[row, 2].Value = "VerticalAlignmentStyle.Top";
    // Set row height to 30 points.
    ws.Rows[row].Height = 30 * 20;
    ws.Cells[row, 2].Style.VerticalAlignment = VerticalAlignmentStyle.Top;

    ws.Cells[row += 2, 1].Value = ".Style.WrapText";
    ws.Cells[row, 2].Value = "This property is set to true so this text appears broken   into multiple lines.";
    ws.Cells[row, 2].Style.WrapText = true;

    ef.Save("Styles and Formatting.xls");
 }
}

最佳答案

确保您在解决方案资源管理器的引用下引用了 System.Drawing dll。

任何 .NET 类都记录在 MSDN 中,每次您都会看到命名空间和它“所在”的程序集。

必须在 Solution Explorer 中的 References 下添加程序集,并且必须使用 using 指令将命名空间添加到您的代码中.

例如,这是来自 MSDN 的 Color 类的快照:

enter image description here

http://msdn.microsoft.com/en-us/library/system.drawing.color(v=vs.110).aspx

干杯

关于c# - 在当前上下文中不存在 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22572579/

相关文章:

c++ - 带有 Visual Studio 2013 的 libffi

c# - 为什么 Interlocked.Exchange 触发警告 CS4014?

c# - Visual Studio 2013 C++ 智能感知

c# - 通过传递逗号分隔值删除记录 SQL Server 和 C#

c# - 如何在没有类型参数的情况下调用 Func?

c# - 从 WebMethod 传递参数到 Jquery

visual-studio-2013 - Visual Studio 2013 - 慢速扩展或加载项 - 如何找到哪一个?

C# - 如何在运行时测试哪个 COM coclass 用于实例化接口(interface)?

c# - 如何进行批量插入——Linq to Entities

c# - 如何解决 Microsoft.VisualStudio.ExtensionManager.MissingReferencesException