Excel i Python Verisine Dönüştürme

Excel Çalışma Kitabını Sözlüğe Nasıl Dönüştürülür

Aspose.Cells for Python via .NET kullanarak excel verilerini sözlüğe nasıl aktaracağınızı gösteren örnek bir kod parçası aşağıda verilmiştir:

  1. Örnek dosyayı yükleyin.
  2. Tüm çalışma sayfalarını gezin ve Aspose.Cells for Python Excel kütüphanesini kullanarak çalışma kitabını sözlüğe dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# excel to Dictionary
sheet_count = book.worksheets.capacity - 1
excel_dict = {}
for sheet_index in range(0, sheet_count):
worksheet_list =[]
sheet = book.worksheets.get(sheet_index)
cells = sheet.cells
rows = cells.rows
max_column_index = cells.max_column + 1
row_count = rows.count
index = -1
for row_index in range(0, row_count):
row = rows.get_row_by_index(row_index)
if row_index != row.index:
for blank_row_index in range(index+1, row.index):
blank_row =[]
for blank_column_index in range(0,max_column_index):
blank_row.append("")
worksheet_list.append(blank_row)
data_row =[]
for column_index in range(0,max_column_index):
curr_cell = cells.check_cell(row.index, column_index)
if curr_cell:
data_row.append(curr_cell.value)
else:
data_row.append("")
worksheet_list.append(data_row)
index = row.index
excel_dict[sheet.name] = worksheet_list
print(excel_dict)

Çıktı sonucu:

{'Sheet1': [['City', 'Region', 'Store'], ['Chicago', 'Central', 3055], ['New York', 'East', 3036], ['Detroit', 'Central', 3074]], 'Sheet2': [['City2', 'Region2', 'Store3'], ['Seattle', 'West', 3000], ['philadelph', 'East', 3082], ['Detroit', 'Central', 3074]], 'Sheet3': [['City3', 'Region3', 'Store3'], ['Seattle', 'West', 3166], ['New York', 'East', 3090], ['Chicago', 'Central', 3055]]}

Excel Çalışma Kitabını Listeye Nasıl Dönüştürülür

Excel verilerini liste olarak dışa aktarmak için Aspose.Cells for Python via .NET kullanarak örnek kod parçası:

  1. Örnek dosyayı yükleyin.
  2. Tüm çalışma sayfalarını gezin ve Aspose.Cells for Python Excel kütüphanesini kullanarak çalışma kitabını listede dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# workbook to list
sheet_count = book.worksheets.capacity - 1
workbook_list = []
for sheet_index in range(0, sheet_count):
worksheet_list =[]
sheet = book.worksheets.get(sheet_index)
cells = sheet.cells
rows = cells.rows
max_column_index = cells.max_column + 1
row_count = rows.count
index = -1
for row_index in range(0, row_count):
row = rows.get_row_by_index(row_index)
if row_index != row.index:
for blank_row_index in range(index+1, row.index):
blank_row =[]
for blank_column_index in range(0,max_column_index):
blank_row.append("")
worksheet_list.append(blank_row)
data_row =[]
for column_index in range(0,max_column_index):
curr_cell = cells.check_cell(row.index, column_index)
if curr_cell:
data_row.append(curr_cell.value)
else:
data_row.append("")
worksheet_list.append(data_row)
index = row.index
workbook_list.append(worksheet_list)
print(workbook_list)

Çıktı sonucu:

[[['City', 'Region', 'Store'], ['Chicago', 'Central', 3055], ['New York', 'East', 3036], ['Detroit', 'Central', 3074]], 
[['City2', 'Region2', 'Store3'], ['Seattle', 'West', 3000], ['philadelph', 'East', 3082], ['Detroit', 'Central', 3074]], [['City3', 'Region3', 'Store3'], ['Seattle', 'West', 3166], ['New York', 'East', 3090], ['Chicago', 'Central', 3055]]] 

Excel Çalışma Sayfasını Listeye Nasıl Dönüştürülür

Excel çalışma sayfası verilerini liste olarak dışa aktarmak için Aspose.Cells for Python via .NET kullanarak örnek kod parçası:

  1. Örnek dosyayı yükleyin.
  2. İlk elektronik tabloyu alın.
  3. Aspose.Cells for Python Excel kütüphanesini kullanarak çalışma sayfası verilerini liste olarak dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# Get the first worksheet
sheet1 = book.worksheets.get(0)
cells = sheet1.cells
rows = cells.rows
max_column_index = sheet1.cells.max_column + 1
# worksheet to list
worksheet_list =[]
row_count = rows.count
index = -1
for row_index in range(0, row_count):
row = rows.get_row_by_index(row_index)
if row_index != row.index:
for blank_row_index in range(index+1, row.index):
blank_row =[]
for blank_column_index in range(0,max_column_index):
blank_row.append("")
worksheet_list.append(blank_row)
data_row =[]
for column_index in range(0,max_column_index):
curr_cell = cells.check_cell(row.index, column_index)
if curr_cell:
data_row.append(curr_cell.value)
else:
data_row.append("")
worksheet_list.append(data_row)
index = row.index
print(worksheet_list)

Çıktı sonucu:

[['City', 'Region', 'Store'], ['Chicago', 'Central', 3055], ['New York', 'East', 3036], ['Detroit', 'Central', 3074]]

Excel ListObject’ini Listeye Nasıl Dönüştürülür

Aspose.Cells for Python via .NET kullanarak ListObject verilerini liste olarak dışa aktarmak için örnek kod parçası:

  1. Örnek dosyayı yükleyin.
  2. İlk elektronik tabloyu alın.
  3. ListObject nesnesi oluşturun. Aspose.Cells for Python Excel kütüphanesini kullanarak ListObject verilerini liste olarak dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# Get the first worksheet
sheet1 = book.worksheets.get(0)
cells = sheet1.cells
# listobject to list
table_index = sheet1.list_objects.add("A1", "C4", True)
table = sheet1.list_objects[table_index]
table_list =[]
for row_index in range(table.start_row , table.end_row + 1):
row =[]
for column_index in range(table.start_column, table.end_column + 1):
curr_cell = cells.check_cell(row_index, column_index)
if curr_cell:
row.append(curr_cell.value)
else:
row.append("")
table_list.append(row)
print(table_list)

Çıktı sonucu:

[['City', 'Region', 'Store'], ['Chicago', 'Central', 3055], ['New York', 'East', 3036], ['Detroit', 'Central', 3074]]

Excel Satırını Listeye Nasıl Dönüştürülür

Aspose.Cells for Python via .NET kullanarak Satır verilerini liste olarak dışa aktarmak için örnek kod parçası:

  1. Örnek dosyayı yükleyin.
  2. İlk elektronik tabloyu alın.
  3. Satır endeksine göre Satır nesnesini alın. Aspose.Cells for Python Excel kütüphanesini kullanarak Satır verilerini liste olarak dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# Get the first worksheet
sheet1 = book.worksheets.get(0)
cells = sheet1.cells
# row to list
max_column_index = sheet1.cells.max_column + 1
row_index = cells.max_data_row
row_list = []
for column_index in range(0,max_column_index):
curr_cell = cells.check_cell(row_index, column_index)
if curr_cell:
row_list.append(curr_cell.value)
else:
row_list.append("")
print(row_list)

Çıktı sonucu:

['Detroit', 'Central', 3074]

Excel Sütununu Listeye Nasıl Dönüştürülür

Aspose.Cells for Python via .NET kullanarak Sütun verilerini liste olarak dışa aktarmak için örnek kod parçası:

  1. Örnek dosyayı yükleyin.
  2. İlk elektronik tabloyu alın.
  3. Sütun dizinine göre Sütun nesnesini alın.
  4. Aspose.Cells for Python Excel kütüphanesini kullanarak Sütun verisini listeye dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# Get the first worksheet
sheet1 = book.worksheets.get(0)
cells = sheet1.cells
# column to list
max_row_index = sheet1.cells.max_row + 1
column_index = cells.max_data_column
column_list = []
for row_index in range(0,max_row_index):
curr_cell = sheet1.cells.check_cell(row_index, column_index)
if curr_cell:
column_list.append(curr_cell.value)
else:
column_list.append("")
print(column_list)

Çıktı sonucu:

['Store', 3055, 3036, 3074]

Excel’den Listeye Nasıl Dönüştürülür

Aspose.Cells for Python via .NET kullanarak aralık verisini listeye nasıl aktaracağınızı gösteren örnek kod parçası:

  1. Örnek dosyayı yükleyin.
  2. İlk elektronik tabloyu alın.
  3. Aralık oluşturun.
  4. Aspose.Cells for Python Excel kütüphanesini kullanarak Aralık verisini listeye dönüştürün.
import aspose.cells
from aspose.cells import Workbook, Worksheet, Range
# Open the Excel workbook
book = Workbook("sample_data.xlsx")
# Get the first worksheet
sheet1 = book.worksheets.get(0)
# range to list
cells = sheet1.cells
range_obj = cells.create_range("B1", "C3")
range_list =[]
for row_index in range(range_obj.first_row , range_obj.first_row + range_obj.row_count ):
row =[]
for column_index in range(range_obj.first_column, range_obj.first_column + range_obj.column_count):
curr_cell = cells.check_cell(row_index, column_index)
if curr_cell:
row.append(curr_cell.value)
else:
row.append("")
range_list.append(row)
print(range_list)

Çıktı sonucu:

[['Region', 'Store'], ['Central', 3055], ['East', 3036]]