log ClosedXML

Microsoft Visual Studio

1. NuGet Package Manager installs ClosedXML that depends DocumentFormat.OpenXml, ExcelNumberFormat, and WindowsBase.

2.using ClosedXML.Excel;
using System;
using System.Data;
using System.Data.OleDb;
using System.IO;
3. read .xlsx file
using (var workbook = new XLWorkbook(xlsxfile))
{
...
  var ws = workbook.Worksheet(1);
  foreach (var row in ws.Rows())
  {if (!row.IsEmpty()){string cell1 = row.Cell(1).GetValue<string>();
                                     object value =row.Cell(1).Value; }
  }
}

4. OpenFileDialog
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = Form1.XlsxInitialDirectory; // "C:\\Users\\jason\\Downloads\\";
                openFileDialog.Filter = "xlsx files (*.xlsx)|*.xlsx"; //"txt files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
                openFileDialog.FilterIndex = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;
                    txtXlsx.Text = filePath;
                    //Read the contents of the file into a stream
                    //var fileStream = openFileDialog.OpenFile();
                    //using (StreamReader reader = new StreamReader(fileStream))
                    //{
                    //    fileContent = reader.ReadToEnd();
                    //}
                }
            }
5.FolderBrowserDialog
using (FolderBrowserDialog folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog())
            {
                folderBrowserDialog1.Description ="Select the directory that you want to store SQL Script as the default.";
                folderBrowserDialog1.ShowNewFolderButton = false;
                folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;//.Personal;
                DialogResult result = folderBrowserDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    txtSqlDirectory.Text = folderBrowserDialog1.SelectedPath;
                }
            }
6.System.IO.StreamWriter
             // using (file = new System.IO.StreamWriter(sqLpathFile, false))
            //  using (System.IO.StreamWriter file =
            //             new System.IO.StreamWriter(@"D:\jinchen\nt4.txt", true))
            //         {
            //             file.WriteLine("Fourth line");
            //         }
7.System.IO.Directory
   if (!Directory.Exists(sqlPath))
   {  Directory.CreateDirectory(sqlPath);  }
8.System.IO.File
if (!File.Exists(sqLpathFile))
                {
                    // Create a file to write to.
                    using (StreamWriter sw = File.CreateText(sqLpathFile))
                    {
                        sw.WriteLine("Hello");
                    }
                }

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE