고정 폭 텍스트 파일로 Excel 스프레드 시트를 내보내시겠습니까? 너비 텍스트 파일을 가져와 열에 넣을 필드의

Excel에는 고정 너비 텍스트 파일을 가져와 열에 넣을 필드의 시작과 끝 위치를 선택할 수있는 대화 상자가 표시되는 기능이 있습니다.

기존 스프레드 시트에서 고정 너비 텍스트 파일로 내보낼 수있는 기능도 있습니까?

그렇다면 어떻게 액세스합니까? 다른 이름으로 저장을 사용하고 텍스트 파일을 선택하려고 시도했지만 도움이되지 않는 탭 구분으로 만 저장하는 것 같습니다.

중요한 경우 Excel 2003입니다.



답변

기본 Excel 기능에서 얻을 수있는 가장 가까운 것은 다른 이름 으로 저장 | 서식있는 텍스트 (공백으로 구분) (*. prn) . 너비를 자동으로 결정하고 필요에 따라 해당 너비에 맞출 공간을 삽입합니다.

그 외에도 더 많은 작업을 수행 할 수있는 매크로 또는 기타 추가 기능이 필요합니다.


답변

Office Professional이있는 경우 Access에서 Excel 파일을 연 다음 Access에서 내보내기를 수행 할 수 있습니다. Access를 사용하면 내 보낸 파일에 고정 너비 레이아웃을 지정할 수 있으며 해당 너비를 지정하기위한 매우 세밀한 컨트롤을 제공합니다.


답변

와우, 나는이 질문을 직접 할 예정이지만 이미 요청되었습니다. 모든 Excel 클립 보드 출력은 tab기본적으로 구분됩니다. 이것은 고정 폭 글꼴을 가지고 있지만 반드시 탭 구분 기호를 지원할 필요는 없을 때 “실제”일반 텍스트 출력에 귀찮습니다.

어쨌든, 현재 선택한 영역을 간단한 고정 너비 열 ASCII 테이블로 복사하는 작은 Excel 매크로를 찾아서 수정했습니다.

187712 201 37 0.18
2525580149 0.25
136829137 43 0.31

다음은 매크로 코드입니다. 사용하려면 Excel 2007 이상을 사용하는 경우 Excel 옵션에서 개발자 탭활성화 해야합니다 .

Sub CopySelectionToClipboardAsText()

   ' requires a reference to "Windows Forms 2.0 Object Library"
   ' add it via Tools / References; if it does not appear in the list
   ' manually add it as the path C:\Windows\System32\FM20.dll

    Dim r As Long, c As Long
    Dim selectedrows As Integer, selectedcols As Integer

    Dim arr
    arr = ActiveSheet.UsedRange
    selectedrows = UBound(arr, 1)
    selectedcols = UBound(arr, 2)

    Dim temp As Integer
    Dim cellsize As Integer
    cellsize = 0
    For c = 1 To selectedcols
        temp = Len(CStr(Cells(1, c)))
        If temp > cellsize Then
            cellsize = temp
        End If
    Next c
    cellsize = cellsize + 1

    Dim line As String
    Dim output As String

    For r = 1 To selectedrows
        line = Space(selectedcols * cellsize)
        For c = 1 To selectedcols
            Mid(line, c * cellsize - cellsize + 1, cellsize) = Cells(r, c)
        Next c
        output = output + line + Chr(13) + Chr(10)
    Next r

    Dim MyData As MSForms.DataObject
    Set MyData = New DataObject
    MyData.SetText output
    MyData.PutInClipboard

    MsgBox "The current selection was formatted and copied to the clipboard"

End Sub

답변

먼저 데이터를 Courier New (또는 다른 고정 너비 글꼴)로 형식화하십시오. 그런 다음 .prn으로 저장하면 고정 너비가 고정됩니다.


답변

Jeff Atwood의 답변을 확장하면 설명 할 수 없기 때문에 :

열 너비를 해당 열에서 가장 넓은 셀로 설정하고 각 열에 자체 너비를 갖도록 매크로를 수정했습니다. 그의 매크로는 첫 번째 행에서 가장 넓은 셀만 찾은 다음 모든 열의 너비를 설정했습니다.

Sub CopySelectionToClipboardAsText()

   ' requires a reference to "Windows Forms 2.0 Object Library"
   ' add it via Tools / References; if it does not appear in the list
   ' manually add it as the path C:\Windows\System32\FM20.dll

    Dim r As Long, c As Long, linesize As Long
    Dim selectedrows As Integer, selectedcols As Integer

    Dim arr
    arr = ActiveSheet.UsedRange
    selectedrows = UBound(arr, 1)
    selectedcols = UBound(arr, 2)
    ReDim CellSizes(1 To selectedcols, 2) As Integer

    Dim temp As Integer
    Dim cellsize As Integer
    linesize = 0
    For c = 1 To selectedcols
        cellsize = 0
        For r = 1 To selectedrows
            temp = Len(CStr(Cells(r, c)))
            If temp > cellsize Then
                cellsize = temp
            End If
        Next
        CellSizes(c, 0) = cellsize + 1
        CellSizes(c, 1) = linesize
        linesize = linesize + cellsize + 1
    Next c

    Dim line As String
    Dim output As String

    For r = 1 To selectedrows
        line = Space(linesize)
        For c = 1 To selectedcols
            Mid(line, CellSizes(c, 1) + 1, CellSizes(c, 0)) = Cells(r, c)
        Next c
        output = output + line + Chr(13) + Chr(10)
    Next r

    Dim MyData As MSForms.DataObject
    Set MyData = New DataObject
    MyData.SetText output
    MyData.PutInClipboard

    MsgBox "The current selection was formatted and copied to the clipboard"

End Sub

답변

이것은 나를위한 살인자입니다. 몇 가지 옵션도 있습니다.

http://www.sensefulsolutions.com/2010/10/format-text-as-table.html