패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.4.0

docx_template

Docx 템플릿 엔진입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.2천
좋아요
107
Pub 점수
130

패키지 설치

flutter pub add docx_template

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

템플릿 구문을 사용하여 DOCX 파일을 동적으로 생성할 수 있는 Dart 패키지입니다. 사용자는 Word 문서에 자리 표시자를 정의하고 런타임에 실제 데이터로 교체할 수 있으며, 보고서, 송장 또는 증명서를 프로그래밍 방식으로 생성하는 데 이상적입니다. 엔진은 풍부한 텍스트 형식, 이미지 및 테이블을 템플릿 내에서 지원합니다. 크로스플랫폼 사용을 위해 설계되어 Android, iOS, 웹, macOS, Windows, Linux에서 원활하게 작동합니다. 외부 서비스에 의존하지 않고도 가볍고 유연한 문서 자동화 솔루션을 필요로 하는 개발자들을 위한 것입니다.

사용 사례

  • 다이나믹 보고서 생성
  • 인쇄 가능한 송장 만들기
  • 인증서 생성 자동화
  • 표준화된 문서 제작
  • 데이터를 Word 형식으로 내보내기

주요 기능

  • 템플릿 기반의 DOCX 생성
  • 플레이스홀더 및 변수 지원
  • 리치 텍스트 및 이미지 삽입
  • 크로스 플랫폼 호환성
  • 경량이며 종속성 없음
  • Flutter 앱과의 간편한 통합

적합한 대상

  • 문서가 많은 앱을 구축하는 플러터 개발자
  • 보고서 생성이 필요한 비즈니스 애플리케이션
  • 자동 출력을 위한 교육 도구
  • Teams automating paperwork workflows
  • 오프라인 문서 생성을 원하는 개발자

고려 사항

  • DOCX 형식만 지원 (ODT 또는 기타 형식 제외)
  • 복잡한 레이아웃을 위해서는 신중한 템플릿 구조가 필요합니다
  • 매크로와 같은 고급 워드 기능에 대한 내장 지원 없음
  • 정적 또는 반동적 콘텐츠에 가장 적합
  • 매우 큰 템플릿을 사용할 경우 성능이 달라질 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

docx_template_dart

A Docx template engine

Generates docx from template file.

In order to use the library, you need to learn how to insert and edit content control tags in Microsoft Word. LibreOffice and other office programs are not supported because they do not have a content control tag system.

To do this, go to the project repository and download the template file template.docx

Then open the file in Microsoft Word, go to the program settings and enable Developer mode. You may need to restart the program. After that, the developer tab will be available.

In order to make the tags visible, you need to enable "design mode" on the developer tab, to view and edit the tag parameters, you need select tag, then click "properties" button on developer tab.

To create a tag, you need to use the "Aa" buttons on the developer tab, clicking on the button will open a window where: the TAG field can be one from the following list: list, table, text, plain, img the TITLE field is the name of the tag, which will be passed to constructors of the Content classes

For example: If we set the tag equal to 'list' and the title equal to 'cars', then we must use the corresponding ListContent ('cars', [*here contents*])

For the 'text' tag and the title equal to 'block_name' we use: TextContent('block_name', 'Example text') etc.

List of supported tags:

  • list - a list, which can contain the following tags: text, plain
  • table - table row
  • text - a simple text field
  • plain - a block that can contain text, tables, images, lists, which can be repeated several times if you wrap it in a list tag
  • img - block with a picture, can be used in text or inside tables

Example

  final f = File("template.docx");
  final docx = await DocxTemplate.fromBytes(await f.readAsBytes());

  /* 
    Or in the case of Flutter, you can use rootBundle.load, then get bytes
    
    final data = await rootBundle.load('lib/assets/users.docx');
    final bytes = data.buffer.asUint8List();

    final docx = await DocxTemplate.fromBytes(bytes);
  */

  // Load test image for inserting in docx
  final testFileContent = await File('test.jpg').readAsBytes();

  final listNormal = ['Foo', 'Bar', 'Baz'];
  final listBold = ['ooF', 'raB', 'zaB'];

  final contentList = <Content>[];

  final b = listBold.iterator;
  for (var n in listNormal) {
    b.moveNext();

    final c = PlainContent("value")
      ..add(TextContent("normal", n))
      ..add(TextContent("bold", b.current));
    contentList.add(c);
  }

  Content c = Content();
  c
    ..add(TextContent("docname", "Simple docname"))
    ..add(TextContent("passport", "Passport NE0323 4456673"))
    ..add(TableContent("table", [
      RowContent()
        ..add(TextContent("key1", "Paul"))
        ..add(TextContent("key2", "Viberg"))
        ..add(TextContent("key3", "Engineer"))
        ..add(ImageContent('img', testFileContent)),
      RowContent()
        ..add(TextContent("key1", "Alex"))
        ..add(TextContent("key2", "Houser"))
        ..add(TextContent("key3", "CEO & Founder"))
        ..add(ListContent("tablelist", [
          TextContent("value", "Mercedes-Benz C-Class S205"),
          TextContent("value", "Lexus LX 570")
        ]))
        ..add(ImageContent('img', testFileContent))
    ]))
    ..add(ListContent("list", [
      TextContent("value", "Engine")
        ..add(ListContent("listnested", contentList)),
      TextContent("value", "Gearbox"),
      TextContent("value", "Chassis")
    ]))
    ..add(ListContent("plainlist", [
      PlainContent("plainview")
        ..add(TableContent("table", [
          RowContent()
            ..add(TextContent("key1", "Paul"))
            ..add(TextContent("key2", "Viberg"))
            ..add(TextContent("key3", "Engineer")),
          RowContent()
            ..add(TextContent("key1", "Alex"))
            ..add(TextContent("key2", "Houser"))
            ..add(TextContent("key3", "CEO & Founder"))
            ..add(ListContent("tablelist", [
              TextContent("value", "Mercedes-Benz C-Class S205"),
              TextContent("value", "Lexus LX 570")
            ]))
        ])),
      PlainContent("plainview")
        ..add(TableContent("table", [
          RowContent()
            ..add(TextContent("key1", "Nathan"))
            ..add(TextContent("key2", "Anceaux"))
            ..add(TextContent("key3", "Music artist"))
            ..add(ListContent(
                "tablelist", [TextContent("value", "Peugeot 508")])),
          RowContent()
            ..add(TextContent("key1", "Louis"))
            ..add(TextContent("key2", "Houplain"))
            ..add(TextContent("key3", "Music artist"))
            ..add(ListContent("tablelist", [
              TextContent("value", "Range Rover Velar"),
              TextContent("value", "Lada Vesta SW Sport")
            ]))
        ])),
    ]))
    ..add(ListContent("multilineList", [
      PlainContent("multilinePlain")
        ..add(TextContent('multilineText', 'line 1')),
      PlainContent("multilinePlain")
        ..add(TextContent('multilineText', 'line 2')),
      PlainContent("multilinePlain")
        ..add(TextContent('multilineText', 'line 3'))
    ]))
    ..add(TextContent('multilineText2', 'line 1\nline 2\n line 3'))
    ..add(ImageContent('img', testFileContent));

  final d = await docx.generate(c);
  final of = File('generated.docx');
  if (d != null) await of.writeAsBytes(d);

DocxTemplate.generate takes two additional parameters:

  1. tagPolicy set rules to remove content control tags from the document
  2. imagePolicy Where ImagePolicy.remove - deletes the image if the ImageContent object is not provided ImagePolicy.save - leaves the original images from the template if the ImageContent object is not specified

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.