嗨简单的问题我想进入一个文件夹查找 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
并将字体颜色编辑为黑色(如果它是红色的)。我正在寻找如何使用 C# 读取 Excel 文件的数据?马上。