Excel 워크북에서 원시 텍스트를 추출하는 것은 데이터 파이프라인을 구축하거나 간단한 보고서를 생성할 때 자주 필요한 작업입니다. Python에서 Excel 워크북을 텍스트로 변환하는 방법을 알고 싶다면, GroupDocs.Conversion Cloud SDK for Python을 사용하면 간단합니다. 이 가이드는 SDK 설치, 워크북 업로드, 변환 옵션 구성 및 순수 TXT 결과 가져오기까지 단계별로 안내합니다. 끝까지 따라 하면 재사용 가능한 스크립트와 REST‑based 자동화를 위한 cURL 명령 세트를 얻게 됩니다.

시작하기 전에: 전제 조건 및 설치

시작하기 전에 다음이 있는지 확인하십시오:

  • Python 3.7 이상이 머신에 설치되어 있어야 합니다.
  • 활성화된 GroupDocs Cloud 계정(클라이언트 ID 및 클라이언트 시크릿).
  • GroupDocs Cloud 엔드포인트에 대한 네트워크 액세스.

pip을 통해 SDK를 설치합니다:

pip install groupdocs-conversion-cloud

최신 패키지는 공식 릴리스 페이지에서 다운로드할 수 있습니다. 설치 후, 자격 증명을 환경 변수로 설정하거나 나중에 코드의 자리 표시자를 교체하십시오. SDK가 준비되면 변환 프로세스를 시작할 준비가 된 것입니다.

단계별 구축: Python에서 Excel 워크북을 텍스트로 변환하는 방법

1단계: 자격 증명 구성

먼저, Configuration 객체를 생성하고 클라이언트 ID와 비밀 키를 제공하십시오. 이 객체는 이후 모든 API 호출에 사용됩니다.

import os
from groupdocs_conversion_cloud import Configuration

client_id = os.getenv("GROUPDOCS_CLIENT_ID", "YOUR_CLIENT_ID")
client_secret = os.getenv("GROUPDOCS_CLIENT_SECRET", "YOUR_CLIENT_SECRET")

config = Configuration()
config.client_id = client_id
config.client_secret = client_secret

Configuration 클래스는 API reference에 문서화되어 있습니다.

2단계: Excel 워크북 업로드

로컬 Excel 파일을 GroupDocs Cloud 스토리지에 업로드합니다. 파일이 이미 클라우드에 있는 경우 이 단계는 선택 사항입니다.

from groupdocs_conversion_cloud import ApiClient, UploadFileApi, UploadFileRequest

api_client = ApiClient(config)
upload_api = UploadFileApi(api_client)

local_excel_path = "sample.xlsx"
remote_excel_path = "sample.xlsx"

with open(local_excel_path, "rb") as f:
    upload_request = UploadFileRequest(
        path=remote_excel_path,
        file=f.read()
    )
    upload_api.upload_file(upload_request)

UploadFileApi는 파일 전송을 처리합니다; 자세한 내용은 문서를 참조하십시오.

3단계: 변환 옵션 정의

페이지 범위와 같은 선택적 매개변수를 지정하려면 TxtConvertOptions 객체를 생성합니다. 그런 다음 모든 것을 연결하는 ConvertSettings 객체를 만듭니다.

from groupdocs_conversion_cloud import (
    FileInfo,
    TxtConvertOptions,
    ConvertSettings,
)

file_info = FileInfo()
file_info.file_path = remote_excel_path

txt_options = TxtConvertOptions()
# txt_options.page_number = 1   # Uncomment to start from a specific page
# txt_options.page_count = 1    # Uncomment to limit the number of pages

convert_settings = ConvertSettings()
convert_settings.file_info = file_info
convert_settings.format = "txt"
convert_settings.output_path = "sample.txt"
convert_settings.options = txt_options

TxtConvertOptions 클래스는 변환을 세밀하게 조정할 수 있게 해줍니다; 모든 사용 가능한 필드에 대해서는 공식 문서를 참조하세요.

4단계: 변환 실행

준비된 설정으로 ConvertApi의 convert 메서드를 호출합니다. 응답에는 변환된 파일을 다운로드할 수 있는 URL이 포함됩니다.

from groupdocs_conversion_cloud import ConvertApi, ApiException

convert_api = ConvertApi(api_client)

try:
    conversion_result = convert_api.convert(convert_settings)
    print(f"Conversion succeeded. Download URL: {conversion_result.url}")
except ApiException as e:
    print(f"Conversion failed: {e}")

호출이 성공하면 TXT 파일에 대한 직접 다운로드 링크를 받게 됩니다.

5단계: 결과 가져오기

이전 단계에서 제공된 URL을 사용하여 평문 텍스트 파일을 로컬 환경에 다운로드하거나 애플리케이션에서 추가로 처리하십시오.

팁: 간단한 requests.get() 호출을 사용하여 다운로드를 자동화할 수 있으며, 변환 요청에 사용된 동일한 액세스 토큰을 통해 인증을 처리합니다.

이 단계들을 통해 이제 GroupDocs 라이브러리를 사용하여 Python에서 Excel 워크북을 텍스트로 변환하는 방법에 대한 전체 워크플로우를 갖게 되었습니다.

Excel 워크북 텍스트 변환 - 전체 코드 예제

다음 예제는 시작부터 끝까지 전체 구현을 보여줍니다.

import os
from groupdocs_conversion_cloud import (
    Configuration,
    ApiClient,
    UploadFileApi,
    UploadFileRequest,
    ConvertApi,
    ConvertSettings,
    FileInfo,
    TxtConvertOptions,
    ApiException,
)

def main():
    # ----------------------------------------------------------------------
    # 1. Configure credentials (replace placeholders or set env variables)
    # ----------------------------------------------------------------------
    client_id = os.getenv("GROUPDOCS_CLIENT_ID", "YOUR_CLIENT_ID")
    client_secret = os.getenv("GROUPDOCS_CLIENT_SECRET", "YOUR_CLIENT_SECRET")

config = Configuration()
    config.client_id = client_id
    config.client_secret = client_secret

api_client = ApiClient(config)

# ----------------------------------------------------------------------
    # 2. Upload local Excel workbook to GroupDocs Cloud storage (optional)
    # ----------------------------------------------------------------------
    local_excel_path = "sample.xlsx"          # path to the Excel file on your machine
    remote_excel_path = "sample.xlsx"         # path where the file will be stored in the cloud

upload_api = UploadFileApi(api_client)
    try:
        with open(local_excel_path, "rb") as f:
            upload_request = UploadFileRequest(
                path=remote_excel_path,
                file=f.read()
            )
            upload_api.upload_file(upload_request)
        print(f"Uploaded '{local_excel_path}' to cloud storage as '{remote_excel_path}'.")
    except (ApiException, IOError) as e:
        print(f"Failed to upload file: {e}")
        return

# ----------------------------------------------------------------------
    # 3. Prepare conversion settings to transform Excel → plain text
    # ----------------------------------------------------------------------
    convert_api = ConvertApi(api_client)

file_info = FileInfo()
    file_info.file_path = remote_excel_path          # source file in cloud storage

txt_options = TxtConvertOptions()
    # (optional) you can limit conversion to specific pages:
    # txt_options.page_number = 1
    # txt_options.page_count = 1

convert_settings = ConvertSettings()
    convert_settings.file_info = file_info
    convert_settings.format = "txt"                  # target format
    convert_settings.output_path = "sample.txt"      # result file name in cloud storage
    convert_settings.options = txt_options

# ----------------------------------------------------------------------
    # 4. Execute conversion
    # ----------------------------------------------------------------------
    try:
        conversion_result = convert_api.convert(convert_settings)
        # The result contains a URL to download the converted file
        print(f"Conversion succeeded. Download URL: {conversion_result.url}")
    except ApiException as e:
        print(f"Conversion failed: {e}")

if __name__ == "__main__":
    main()

Note: 이 코드 예제는 핵심 기능을 보여줍니다. 프로젝트에 사용하기 전에 파일 경로와 구성 값을 실제 환경에 맞게 업데이트하고, 모든 필수 종속성이 올바르게 설치되었는지 확인하며, 개발 환경에서 충분히 테스트하십시오. 문제가 발생하면 공식 문서를 참조하거나 지원 팀에 문의하십시오.

cURL 및 REST API를 사용한 Excel 텍스트 변환

순수 REST 방식을 선호한다면, 동일한 변환을 cURL 명령으로 수행할 수 있습니다.

  1. 액세스 토큰 얻기
curl -X POST "https://api.groupdocs.cloud/v2.0/connect/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
  1. 소스 Excel 파일 업로드
curl -X PUT "https://api.groupdocs.cloud/v2.0/storage/file/sample.xlsx" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/octet-stream" \
     --data-binary @sample.xlsx
  1. TXT 변환 시작
curl -X POST "https://api.groupdocs.cloud/v2.0/conversion/convert" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/json" \
     -d '{
           "fileInfo": { "filePath": "sample.xlsx" },
           "format": "txt",
           "outputPath": "sample.txt",
           "options": {}
         }'
  1. 변환된 TXT 파일 다운로드
curl -X GET "https://api.groupdocs.cloud/v2.0/storage/file/sample.txt" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -o sample.txt

이 명령은 인증부터 다운로드까지 전체 수명 주기를 보여줍니다. 추가 매개변수 및 오류 처리에 대해서는 API 참조를 참조하십시오.

Excel 변환 설정 구성

SDK는 출력 맞춤을 위한 여러 옵션을 제공합니다. 아래는 Excel‑to‑TXT 변환에 가장 유용한 설정입니다:

  • 페이지 번호 - 특정 시트 또는 페이지부터 변환을 시작합니다.
    txt_options.page_number = 1
    
  • 페이지 수 - 변환할 시트/페이지 수를 제한합니다.
    txt_options.page_count = 2
    
  • 출력 경로 - 클라우드 저장소에 생성되는 TXT 파일의 이름과 위치를 정의합니다.
    convert_settings.output_path = "output/sample.txt"
    

API 참조에서 encoding 또는 preserveFormatting과 같은 기타 고급 옵션을 사용할 수 있습니다; 정확한 요구 사항에 맞게 이를 탐색하십시오.

최종 생각

Python에서 Excel 워크북을 일반 텍스트로 변환하는 것이 이제는 간단하고 반복 가능한 프로세스가 되었습니다. 이는 GroupDocs.Conversion Cloud SDK for Python 덕분입니다. SDK는 인증, 파일 저장 및 변환을 백그라운드에서 처리하여 비즈니스 로직에 집중할 수 있게 해줍니다. 라이선스 옵션은 pricing page에서 확인하고, 프로덕션으로 이동하기 전에 평가용으로 temporary license를 받아보세요. 제공된 코드와 cURL 예제를 사용하면 Excel‑to‑TXT 변환을 모든 Python 기반 워크플로우나 마이크로서비스에 통합할 수 있습니다.

자주 묻는 질문

  • Python에서 Excel 워크북을 텍스트로 변환하는 가장 쉬운 방법은 무엇인가요?
    다음 GroupDocs.Conversion Cloud SDK for Python을 사용하십시오. REST 호출을 추상화하고 파일 업로드, 변환 및 다운로드를 위한 깔끔한 Pythonic API를 제공합니다.

  • Excel 워크북의 특정 시트나 페이지만 변환할 수 있나요?
    예. TxtConvertOptions 객체의 page_number와 page_count를 설정하여 특정 시트를 대상으로 할 수 있습니다. 전체 내용은 API reference를 참조하세요.

  • SDK를 사용하려면 GroupDocs 계정이 필요합니까?
    클라이언트 ID와 비밀 키가 포함된 유효한 GroupDocs Cloud 계정이 필요합니다. GroupDocs 포털에서 계정을 생성하고 대시보드에서 자격 증명을 얻을 수 있습니다.

  • Excel을 TXT로 변환할 때 파일 크기 제한이 있나요?
    클라우드 서비스는 변환을 위해 최대 200 MB까지의 파일을 지원합니다. 더 큰 파일은 업로드하기 전에 분할하거나 청크로 처리해야 합니다.

추가 읽기