比如 已导出一个Excel文件  里头有 书名 编码 价格等等。 差不多有100本书的样子
然后 点击一个按钮 把Excel 的书名 按每一本不同的书名 自动创建一个文件夹。 那个文件夹内还要自动创建4个子文件夹 封面 目录 正文 版权页 这个该怎么做啊?
导出的Excel在一个文件夹里 创建的文件夹都在这个大文件夹里
求详细代码!!

解决方案 »

  1.   

        private void button1_Click(object sender, EventArgs e)
            {
                var fileName = @"D:\julio.l.huang\Desktop\test\1.xls";
                var directory = @"D:\julio.l.huang\Desktop\test";
                if (!Directory.Exists(directory))
                    Directory.CreateDirectory(directory);
                string connectionString = ConnectionReadString(fileName);
                var conn = new OleDbConnection(connectionString);
                OleDbCommand command = conn.CreateCommand();            command.CommandText = "select [书名] from [Sheet1$]";
                try
                {
                    conn.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var s = reader[0].ToString();
                        DirectoryInfo info = new DirectoryInfo(directory);
                        var subdirectory = info.CreateSubdirectory( s);                    subdirectory.CreateSubdirectory("封面");
                        subdirectory.CreateSubdirectory("目录");
                        subdirectory.CreateSubdirectory("正文");
                        subdirectory.CreateSubdirectory("版权页");
                    }
                    reader.Close();
                    MessageBox.Show("创建成功");
                }
                catch (Exception)
                {                throw;
                }
                finally
                {
                    if (conn != null && conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                    }
                }        }        private static string ConnectionReadString(string fileName)
            {
                bool isExcel2003 = fileName.EndsWith(".xls");
                string connectionString = string.Format(
                    isExcel2003
                        ? "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;"
                        : "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"",
                    fileName);
                return connectionString;
            }
      

  2.   

    var fileName = @"D:\julio.l.huang\Desktop\test\1.xls";
                var directory = @"D:\julio.l.huang\Desktop\test";
     怎么把这个改成 我 搜索出来的 在意个Textbox里的路径
      

  3.   

    谢谢  JulioHuang
     非常感谢
       再次感谢