참조사이트

Normal ConnectionString : (work for xls files)

Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES;\""

Office 2007 ConnectionString : (work for xlsx files)

Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR=YES;\""

 

private void UseOlebForLoadExcel()
{
	string filePath = "C:\\99.download\\샘플.xlsx";

	int nOutputRow = 0;
	string sSheetName = null;
	string sConnection = null;
	DataTable dtTablesList = default(DataTable);
	OleDbCommand oleExcelCommand = default(OleDbCommand);
	OleDbDataReader oleExcelReader = default(OleDbDataReader);
	OleDbConnection oleExcelConnection = default(OleDbConnection);


	sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ filePath + ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=1\"";

	oleExcelConnection = new OleDbConnection(sConnection);
	oleExcelConnection.Open();

	dtTablesList = oleExcelConnection.GetSchema("Tables");

	if (dtTablesList.Rows.Count > 0)
	{
		SheetName = dtTablesList.Rows[0]["TABLE_NAME"].ToString();
	}

	dtTablesList.Clear();
	dtTablesList.Dispose();

	if (!string.IsNullOrEmpty(sSheetName))
	{
		oleExcelCommand = oleExcelConnection.CreateCommand();
		oleExcelCommand.CommandText = "Select * From [" + sSheetName + "]";
		oleExcelCommand.CommandType = CommandType.Text;
		oleExcelReader = oleExcelCommand.ExecuteReader();
		nOutputRow = 0;

		while (oleExcelReader.Read())
		{
			// reader.GetDouble(0);
			var index = grid.Rows.Add();
			grid.Rows[index].Cells["filePath"].Value = oleExcelReader.GetString(0);
			grid.Rows[index].Cells["fileName"].Value = oleExcelReader.GetString(0);
			grid.Rows[index].Cells["lineNo"].Value = oleExcelReader.GetString(0);
			grid.Rows[index].Cells["fileCnts"].Value = oleExcelReader.GetString(0);
		}
		oleExcelReader.Close();
	}
	oleExcelConnection.Close();
}

'Programming Language > C#' 카테고리의 다른 글

ChartFX Help  (0) 2020.01.19
remove comments with C#  (0) 2019.10.14
c# 관련사이트  (0) 2019.10.14
Highlight Textbox  (0) 2019.10.14
Visual Studio Installer 를 이용한 배포(Deployment)  (0) 2019.10.14

1.방법 Hyperlink 를 사용해서 열거나,

 

2.vba를 이용하거나.

2번째 벙법으로 하면,
1) 파일을 매크로가 가능한 xlsm파일 형식으로 다른이름으로 저장하고,
2) Alt+F11을 눌러서, 코딩이 가능한 VBA 모드로 변환한다.
3) 해당 시트를 클릭해서, 아래 코드를 붙여 넣기 하고, 저장한다(Ctrl+S).여기서, 파일경로는 1행, 라인은 13라인.
4) 마지막으로, openFileInNotePad.bat 파일을 만든다.

 

# 1. VBA 의 해당 시트 코딩

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 13 Then  // 이벤트가 실행될 컬럼
        Dim filePath As String
        Dim lineNo As String
        Dim RetVal As Integer
            
        filePath = Cells(Target.Row, 1) // 1: 파일경로를 가져올 컬럼
        lineNo = Cells(Target.Row, 5)   // 5: 파일라인을 가져올 컬럼
        If Target.Row > 1 And filePath <> "" Then
            RetVal = MsgBox("Run Batch", vbYesNo)
            If RetVal = 6 Then
                RetVal = Shell("C:\openFileInNotepad.bat" & " " & filePath & " " & lineNo, 1)
            End If
        End If
    End If
End Sub

 

# 2. openFileInNotePad.bat 코딩

"C:\Program Files (x86)\Notepad++\notepad++.exe" "%1" -n%2

 

 

end.

1.Sample Code

2.Component

 

 

'Programming Language > C#' 카테고리의 다른 글

ChartFX Help  (0) 2020.01.19
remove comments with C#  (0) 2019.10.14
excel upload faster  (0) 2019.10.14
Highlight Textbox  (0) 2019.10.14
Visual Studio Installer 를 이용한 배포(Deployment)  (0) 2019.10.14

 

'Programming Language > C#' 카테고리의 다른 글

ChartFX Help  (0) 2020.01.19
remove comments with C#  (0) 2019.10.14
excel upload faster  (0) 2019.10.14
c# 관련사이트  (0) 2019.10.14
Visual Studio Installer 를 이용한 배포(Deployment)  (0) 2019.10.14

+ Recent posts