Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# excel单元格格式_C#_Excel - Fatal编程技术网

C# excel单元格格式

C# excel单元格格式,c#,excel,C#,Excel,如何以编程方式将单元格格式更改为Excel中的文本?我回答此问题和其他Excel查询的方式是:在Excel中记录宏,执行我希望看到的操作,然后查看宏以查看它记录了什么 这样,问题的答案是: Selection.NumberFormat=“@”您可以使用: Range("A1").NumberFormat = "@" 用于文本 Range("A1").NumberFormat = "dd/mm/yyyy hh:mm:ss" 约会 Range("A1").NumberFormat = "#,#

如何以编程方式将单元格格式更改为Excel中的文本?

我回答此问题和其他Excel查询的方式是:在Excel中记录宏,执行我希望看到的操作,然后查看宏以查看它记录了什么

这样,问题的答案是:

Selection.NumberFormat=“@”

您可以使用:

Range("A1").NumberFormat = "@"
用于文本

Range("A1").NumberFormat = "dd/mm/yyyy hh:mm:ss" 
约会

Range("A1").NumberFormat = "#,###"

用于金钱等

将样式应用于命名范围

创建新样式并设置其属性

Excel.Style style = Globals.ThisWorkbook.Styles.Add("NewStyle", missing);

style.Font.Name = "Verdana";
style.Font.Size = 12;
style.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
style.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Gray);
style.Interior.Pattern = Excel.XlPattern.xlPatternSolid;
创建NamedRange控件,为其指定文本,然后应用新样式

Microsoft.Office.Tools.Excel.NamedRange rangeStyles = this.Controls.AddNamedRange(this.Range["A1", missing], "rangeStyles");

rangeStyles.Value2 = "'Style Test";
rangeStyles.Style = "NewStyle";
rangeStyles.Columns.AutoFit();

现在是2012:07:17:20:27,先生,你是我的英雄。