マージされたセルの自動調整|
Contents
[
Hide
]
Microsoft Excelには、セルの高さをその内容に合わせて自動的にサイズ変更する機能があります。この機能は自動行の調整と呼ばれます。Microsoft Excelは、マージされたセルに自動行調整を自然に設定しません。時には、この機能が本当に必要なユーザーにとって、マージされたセルに自動行の調整を実装するのが不可欠になります。
マージセルの自動調整タイプを行の自動調整に使用する方法
Aspose.Cells for Python via .NET は AutoFitterOptions.AutoFitMergedCellsType を使用してこの機能をサポートしています。この API を使用すると、マージセルを含むワークシートの行を自動的に調整することができます。以下に、マージセルの自動調整のすべての可能なタイプの一覧を示します。
- NONE
- 最初の行
- 最終行
- 各行
マージされたセルの行の自動調整
マージセルの行の自動調整

C# サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import AutoFitterOptions, Workbook | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new Workbook | |
wb = Workbook() | |
# Get the first (default) worksheet | |
_worksheet = wb.worksheets[0] | |
# Create a range A1:B1 | |
range = _worksheet.cells.create_range(0, 0, 1, 2) | |
# Merge the cells | |
range.merge() | |
# Insert value to the merged cell A1 | |
_worksheet.cells.get(0, 0).value = "A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end" | |
# Create a style object | |
style = _worksheet.cells.get(0, 0).get_style() | |
# Set wrapping text on | |
style.is_text_wrapped = True | |
# Apply the style to the cell | |
_worksheet.cells.get(0, 0).set_style(style) | |
# Create an object for AutoFitterOptions | |
options = AutoFitterOptions() | |
# Set auto-fit for merged cells | |
options.auto_fit_merged_cells = True | |
# Autofit rows in the sheet(including the merged cells) | |
_worksheet.auto_fit_rows(options) | |
dataDir = dataDir + "AutoFitMergedCells.out.xlsx" | |
# Save the Excel file | |
wb.save(dataDir) |