嗨簡單的問題,我想進入一個文件夾尋找Excel文件。然後進入每個excel文件,並使用c#將紅色字體顏色更改爲黑色。這可能嗎?是否可以使用c#來訪問excel文件?
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#?。
對的,這是可能的。 – 2013-05-03 10:34:02
是的。你到目前爲止有多遠?您可以枚舉目錄中的文件,然後使用EPPlus等來打開和修改Excel文件。 – Simon 2013-05-03 10:35:09
任何事情都是可能的......釋放你的思想 – RedEyedMonster 2013-05-03 10:35:41