테이블 위치 지정

부동 테이블과 인라인 테이블이 있습니다:

  • Inline tables은 텍스트와 동일한 레이어에 배치되며 위와 아래의 표만 둘러싸는 텍스트 흐름에 배치됩니다. 인라인 테이블은 항상 당신이 그들을 배치 단락 사이에 나타납니다.
  • Floating tables은 텍스트 위에 계층화되어 있으며,단락에 대한 테이블의 위치는 테이블 앵커에 의해 결정됩니다. 이 때문에 문서에서 부동 테이블의 위치는 수직 및 수평 위치 설정의 영향을받습니다.

때때로 당신은 특정 방법으로 문서에 테이블을 배치해야합니다. 이렇게 하려면 정렬 도구를 사용하여 테이블과 주변 텍스트 사이의 들여쓰기를 설정해야 합니다.

이 기사에서는Aspose.Words이 포지셔닝을 위해 제공하는 옵션에 대해 설명합니다.

인라인 테이블 위치 지정

Aspose.WordsAPI및Alignment속성을 사용하여 인라인 테이블의 위치를 설정할 수 있습니다. 따라서 문서 페이지를 기준으로 테이블의 정렬을 조정할 수 있습니다.

다음 코드 예제에서는 인라인 테이블의 위치를 설정하는 방법을 보여 줍니다:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Tables.docx");
Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
// Align the table to the center of the page.
table.setAlignment(TableAlignment.CENTER);

플로팅 테이블 정렬 가져오기

테이블 텍스트 줄 바꿈이Around로 설정된 경우RelativeHorizontalAlignmentRelativeVerticalAlignment속성을 사용하여 테이블의 가로 및 세로 정렬을 가져올 수 있습니다.

other types of text wrapping을 사용하면Alignment속성을 사용하여 인라인 테이블 정렬을 얻을 수 있습니다.

다음 코드 예제에서는 테이블의 정렬을 가져오는 방법을 보여 줍니다:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Tables.docx");
Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
if (table.getTextWrapping() == TextWrapping.AROUND)
{
System.out.println(table.getRelativeHorizontalAlignment());
System.out.println(table.getRelativeVerticalAlignment());
}
else
{
System.out.println(table.getAlignment());
}

플로팅 테이블 위치 얻기

부동 테이블의 위치는 다음 속성을 사용하여 결정됩니다:

다음 코드 예제에서는 부동 테이블의 위치를 가져오는 방법을 보여 줍니다:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Table wrapped by text.docx");
for (Table table : doc.getFirstSection().getBody().getTables())
{
// If the table is floating type, then print its positioning properties.
if (table.getTextWrapping() == TextWrapping.AROUND)
{
System.out.println(table.getHorizontalAnchor());
System.out.println(table.getVerticalAnchor());
System.out.println(table.getAbsoluteHorizontalDistance());
System.out.println(table.getAbsoluteVerticalDistance());
System.out.println(table.getAllowOverlap());
System.out.println(table.getAbsoluteHorizontalDistance());
System.out.println(table.getRelativeVerticalAlignment());
System.out.println("..............................");
}
}

플로팅 테이블 위치 설정

얻는 것과 마찬가지로 동일한Aspose.WordsAPI을 사용하여 부동 테이블의 위치를 설정할 수 있습니다.

정렬 및 수평 및 수직 거리가 결합 된 속성이며 하나는 다른 하나를 재설정 할 수 있음을 아는 것이 중요합니다. 예를 들어RelativeHorizontalAlignment을 설정하면AbsoluteHorizontalDistance이 기본값으로 재설정되고 그 반대의 경우도 마찬가지입니다. 수직 배열도 마찬가지입니다.

다음 코드 예제에서는 부동 테이블의 위치를 설정하는 방법을 보여 줍니다:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Table wrapped by text.docx");
Table table = doc.getFirstSection().getBody().getTables().get(0);
table.setAbsoluteHorizontalDistance(10.0);
table.setRelativeVerticalAlignment(VerticalAlignment.CENTER);
doc.save(getArtifactsDir() + "WorkingWithTables.FloatingTablePosition.docx");
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Table wrapped by text.docx");
Table table = doc.getFirstSection().getBody().getTables().get(0);
table.setHorizontalAnchor(RelativeHorizontalPosition.COLUMN);
table.setVerticalAnchor(RelativeVerticalPosition.PAGE);
doc.save(getArtifactsDir() + "WorkingWithTables.RelativeHorizontalOrVerticalPosition.docx");

표와 주변 텍스트 사이의 거리 얻기

Aspose.Words또한 테이블과 주변 텍스트 사이의 거리를 찾을 수있는 기회를 제공합니다:

다음 코드 예제에서는 테이블과 주변 텍스트 사이의 거리를 구하는 방법을 보여 줍니다:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Tables.docx");
System.out.println("\nGet distance between table left, right, bottom, top and the surrounding text.");
Table table = (Table) doc.getChild(NodeType.TABLE, 0, true);
System.out.println(table.getDistanceTop());
System.out.println(table.getDistanceBottom());
System.out.println(table.getDistanceRight());
System.out.println(table.getDistanceLeft());