【发布时间】:2013-05-03 10:33:17
【问题描述】:
您好,问题很简单,我想进入文件夹查找 excel 文件。然后进入每个excel文件并使用c#将红色字体颜色更改为黑色。这可能吗?
namespace Excel_font_color_change
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
List<string> HtmlPathList = new List<string>();
string folderToSearch;
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowNewFolderButton = true;//allow user to create new folders through this dialog
fbd.RootFolder = Environment.SpecialFolder.MyDocuments;//defaults to my computer
System.Windows.Forms.DialogResult dr = fbd.ShowDialog();//make sure user clicks ok
if (dr == DialogResult.OK)
{
folderToSearch = fbd.SelectedPath;//gets folder path
try
{
var allFiles = from files in Directory.EnumerateFiles(folderToSearch, "*.xls*", SearchOption.AllDirectories)
select Path.GetFullPath(files);//gets all files with htm & htm + something for extensions
foreach (string filepath in allFiles)
{
HtmlPathList.Add(filepath);//adds each filepath found to the list
}
}
catch (UnauthorizedAccessException UAEx) { Console.WriteLine(UAEx.Message); }//error handling
catch (PathTooLongException PathEx) { Console.WriteLine(PathEx.Message); }//error handling
Console.WriteLine("1");
}
}
private void button2_Click(object sender, EventArgs e)
{
}
}
这是我到目前为止所拥有的,我希望第二个按钮采用HtmlPathList 中的文件路径,如果字体颜色为红色,则将其编辑为黑色。我现在正在通过How to read data of an Excel file using C#? 寻找。
【问题讨论】:
-
是的,有可能。
-
是的。到目前为止你走了多远?您可以枚举目录中的文件,然后使用 EPPlus 之类的工具打开和修改 Excel 文件。
-
一切皆有可能......解放你的思想
-
@TimSchmelter 您应该将其添加为答案,因为问题是 这可能吗? -_-
-
如果您不想/安装 Office,请查看 Open XML。