请问怎么读取excel文件所有内容为字符串呢
请参阅示例代码,使用 Aspose.Cells for Python 通过 .NET 完成您的任务以供参考。
import aspose.cells
from aspose.cells import Workbook, WorksheetCollection, Worksheet, Cells
# Load the Excel file
workbook = Workbook("e:\\test2\\Book1.xlsx")
# Initialize a string to store the contents
all_contents = ""
# Iterate through all worksheets in the workbook
for sheet_index in range(len(workbook.worksheets)):
sheet = workbook.worksheets[sheet_index]
all_contents += f"Sheet: {sheet.name}\n"
# Get all cells in the sheet
cells = sheet.cells
for row in range(cells.max_data_row + 1):
for col in range(cells.max_data_column + 1):
cell = cells.get(row, col)
# Append the cell's value to the all_contents string
all_contents += f"{cell.string_value}\t"
all_contents += "\n"
all_contents += "\n" # Add a newline to separate sheets
print(all_contents)
希望这能有所帮助。