0

こんにちは、簡単な質問です。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)
        {

        }
    }

これは私がこれまでに持っているものです.2番目のボタンがファイルパスを取得し、 HtmlPathList赤の場合はフォントの色を黒に編集します. C#を使用してExcelファイルのデータを読み取る方法を調べていますか? たった今。

4

2 に答える 2

0

このライブラリをチェックしてください。ただし、xlsxでのみ機能します。

http://www.microsoft.com/en-us/download/details.aspx?id=5124

古い xls ファイルを読みたい場合は、Interop アセンブリを使用できます。

http://www.microsoft.com/en-us/download/details.aspx?id=3508

于 2013-05-03T11:01:34.277 に答える