Satırların ve Sütunların Otomatik Sığdırması

Otomatik Uydurma

Aspose.Cells for Python via .NET, bir Microsoft Excel dosyasını temsil eden bir Workbook sınıfı sağlar. Workbook sınıfı, bir Excel dosyasındaki her çalışma sayfasına erişim sağlayan bir worksheets koleksiyonunu içerir. Bir çalışma sayfası, Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı, bir çalışma sayfasını yönetmek için geniş bir özellik ve yöntem yelpazesi sağlar. Bu makale, Worksheet sınıfını kullanarak satırları veya sütunları otomatik boyutlandırma üzerinde durmaktadır.

Satırı Otomatik Uydurma - Basit

Bir satırın genişlik ve yüksekliğini otomatik ayarlamak için en doğrudan yaklaşım, Worksheet sınıfının auto_fit_row yöntemini çağırmaktır. auto_fit_row yöntemi, yeniden boyutlandırılacak satırın dizinini (satırın dizinini) parametre olarak alır.

from aspose.cells import Workbook
# 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(".")
InputPath = dataDir + "Book1.xlsx"
# Creating a file stream containing the Excel file to be opened
fstream = open(InputPath, "rb")
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Auto-fitting the 3rd row of the worksheet
worksheet.auto_fit_row(1)
# Saving the modified Excel file
workbook.save(dataDir + "output.xlsx")
# Closing the file stream to free all resources
fstream.close()

Hücre Aralığında Satır Otomatik Sığdırma

Bir satır birçok sütundan oluşur. Aspose.Cells for Python via .NET, geliştiricilere, satır içindeki hücre aralığındaki içeriğe göre otomatik olarak bir satırı boyutlandırma olanağı sağlar. Bunun için auto_fit_row yönteminin yüklenmiş versiyonunu çağırarak aşağıdaki parametreleri alır:

  • Satır dizini, otomatik olarak uyarlama yapılacak satırın dizini.
  • İlk sütun dizini, satırın ilk sütununun dizini.
  • Son sütun dizini, satırın son sütununun dizini.

auto_fit_row yöntemi, satırın tüm sütunlarının içeriğini kontrol eder ve ardından satırı otomatik olarak sığdırır.

from aspose.cells import Workbook
# 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(".")
InputPath = dataDir + "Book1.xlsx"
# Creating a file stream containing the Excel file to be opened
fstream = open(InputPath, "rb")
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Auto-fitting the 3rd row of the worksheet
worksheet.auto_fit_row(1, 0, 5)
# Saving the modified Excel file
workbook.save(dataDir + "output.xlsx")
# Closing the file stream to free all resources
fstream.close()

Hücre Aralığında Sütun Otomatik Sığdırma

Bir sütun birçok satırdan oluşur. Bir sütunun, sütun içindeki hücre aralığındaki içeriğe göre otomatik olarak sığdırılması için auto_fit_column yönteminin aşırı yüklenmiş bir sürümü çağrılabilir. Aşağıdaki parametreleri alır:

  • Sütun dizini, otomatik olarak sığdırılacak sütunun dizini.
  • İlk satır indeksi, sütunun ilk satırının indeksi.
  • Son satır indeksi, sütunun son satırının indeksi.

auto_fit_column metodu sütundaki tüm satırların içeriğini kontrol eder ve ardından sütunu otomatik olarak uygun şekilde ayarlar.

from aspose.cells import Workbook
# 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(".")
InputPath = dataDir + "Book1.xlsx"
# Creating a file stream containing the Excel file to be opened
fstream = open(InputPath, "rb")
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Auto-fitting the Column of the worksheet
worksheet.auto_fit_column(4, 4, 6)
# Saving the modified Excel file
workbook.save(dataDir + "output.xlsx")
# Closing the file stream to free all resources
fstream.close()

Birleştirilmiş Hücreler İçin Satırları Otomatik Uydurma

Aspose.Cells for Python via .NET ile AutoFitterOptions APIsini kullanarak bile birleştirilmiş hücreler için satırları otomatik olarak ayarlamak mümkündür. AutoFitterOptions sınıfı, birleştirilmiş hücreler için satırları otomatik olarak ayarlamak için kullanılabilecek auto_fit_merged_cells_type özelliği sağlar. auto_fit_merged_cells_type , aşağıdaki üyelere sahip olan AutoFitMergedCellsType numaralı yenilenebilir değeri kabul eder.

  • YOK: Birleştirilmiş hücreleri yok say.
  • İLK SATIR: Yalnızca ilk satırın yüksekliğini genişletir.
  • SON SATIR: Yalnızca son satırın yüksekliğini genişletir.
  • HER SATIR: Yalnızca her satırın yüksekliğini genişletir.
from aspose.cells import AutoFitMergedCellsType, AutoFitterOptions, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
# 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_type = AutoFitMergedCellsType.EACH_LINE
# Autofit rows in the sheet(including the merged cells)
_worksheet.auto_fit_rows(options)
# Save the Excel file
wb.save(outputDir + "AutofitRowsforMergedCells.xlsx")

Bilinmesi Gerekenler

Gelişmiş Konular