Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using Excel = Microsoft.Office.Interop.Excel;
- using System.IO;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string[][] strFile = new string[][];
- int arrRow=0;
- OpenFileDialog dialog = new OpenFileDialog {
- Filter = "Файлы Excel |*.xlsx"
- };
- if (dialog.ShowDialog() == DialogResult.OK){
- Excel.Application app = new Excel.Application();
- app.Workbooks.Open(dialog.FileName);
- Excel.Workbook book = app.ActiveWorkbook;
- Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1];
- DirectoryInfo dir = new DirectoryInfo(@"F:\");
- foreach(FileInfo files in dir.GetFiles()){
- sheet.Cells[arrRow, 1] = files.Name;
- sheet.Cells[arrRow, 2] = files.Length;
- arrRow++;
- }
- book.Save();
- app.Quit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement