[vb.NET] Tab 파일을 XLSX로 변환
TAB 형식의 파일을 Excel 2007 / 2010 / 2013용 XLSX 파일로 변환해 주는 간단한 유틸입니다.
필요에 의해서 만들어 보았습니다.
웬지 있을것 같아서 10여분 서치해 봤는데 딱 맘에들게 기능하는게 안찾아져서..그냥 후딱 만들었습니다.
파일들 또는 tab 파일이 들어있는 폴더채로 드래그하여 폼에 드롭하면 tab파일 옆에 xlsx로 일괄 변환이 됩니다..
아래 보시다시피 별다른 옵션이나 기능은 없습니다^^;
닷넷프레임워크2.0과 엑셀2007 이상이 설치되어 있으면 됩니다..
조금 변형하면 csv, txt 파일등도 같은방식으로 변환할 수 있을 것 같습니다.
Imports System.IO
Imports XL = Microsoft.Office.Interop.Excel
Public Class frmMain
Private xApp As XL.Application
Private xWB As XL.Workbook
Private xWS As XL.Worksheet
'******************************************************************************************************************************************************
' 파일드롭 처리
'******************************************************************************************************************************************************
Private Sub frmMain_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
Dim FileNames As String() = e.Data.GetData(DataFormats.FileDrop, False)
For Each fNames As String In FileNames
Dim fInfo As DirectoryInfo = New DirectoryInfo(fNames)
If fInfo.Exists Then
Dim fList As FileInfo() = fInfo.GetFiles()
For Each fItem As FileInfo In fList
If fItem.Extension = ".tab" Then
Try
tabtoxlsx(fItem.FullName)
Catch ex As Exception
End Try
End If
Next
Else
Dim fin As FileInfo = New FileInfo(fNames)
If fin.Extension = ".tab" Then
Try
tabtoxlsx(fNames)
Catch ex As Exception
End Try
End If
End If
Next
MessageBox.Show("파일 변환이 완료되었습니다.")
End Sub
Private Sub frmMain_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragOver
e.Effect = DragDropEffects.All
End Sub
Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
xApp = New XL.Application
'xApp.Visible = True
xApp.IgnoreRemoteRequests = True
xApp.ScreenUpdating = False
xApp.DisplayAlerts = False
End Sub
Private Sub frmMain_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
Try : xWB.Close(False) : Catch ex As Exception : End Try
Try
xApp.ScreenUpdating = True
xApp.DisplayAlerts = True
Catch ex As Exception : End Try
Try : xApp.IgnoreRemoteRequests = False : Catch ex As Exception : End Try
Try : xApp.Quit() : Catch ex As Exception : End Try
End Sub
'******************************************************************************************************************************************************
' 탭파일을 열어 엑셀파일로 저장. 형식은 모두 텍스트형식으로 읽는다.
'******************************************************************************************************************************************************
Private Sub tabtoxlsx(tabFileNM As String)
Dim ColArray(0 To 1000, 0 To 1)
For x = 0 To 1000
ColArray(x, 0) = x + 1
ColArray(x, 1) = 2
Next
xApp.Workbooks.OpenText(tabFileNM, Origin:=949, StartRow:=1, DataType:=XL.XlTextParsingType.xlDelimited, Tab:=True, FieldInfo:=ColArray)
xWB = xApp.Workbooks(1)
xWS = xWB.Sheets(1)
xWS.Cells.Font.Size = 10
With xWS.Rows(2)
'.Interior.Pattern = XL.Constants.xlSolid
.Cells.Interior.Color = 14211289
.Font.Bold = True
End With
xWS.Rows(1).Delete(XL.XlDirection.xlUp)
xApp.ActiveWindow.SplitRow = 1
xApp.ActiveWindow.FreezePanes = True
xWB.SaveAs(tabFileNM.Replace(".tab", ".xlsx"), XL.XlFileFormat.xlWorkbookDefault)
xWB.Close(False)
End Sub
End Class
'.NET Develop > Develop' 카테고리의 다른 글
| [.NET] 파일 이름 변경, 복사할 때 동일한 파일이 있으면 자동으로 넘버링 해 주기. (1) | 2013.11.08 |
|---|---|
| [.Net] Datatable을 Access에 Insert하는 방법. (Bulk Insert) (1) | 2013.09.04 |
| [.net] ADO (6.0) + ODBC드라이버를 이용한 DB Connection (MS-SQL, Excel, Access) (0) | 2013.07.04 |
| [.NET] 디렉토리의 파일 목록 조사 + 필터링. Linq와 람다식을 이용한 Directory.GetFiles 확장자 지정하기. (0) | 2013.04.04 |
| [.NET] 시스템 환경변수 Path에 특정 경로 추가하기. (1) | 2013.02.21 |
TAB to XLSX.exe