创建一个 BytesIO 流对象
byte_stream = io.RawIOBase()
将工作簿保存到字节流中(指定保存格式)
workbook.save(stream=byte_stream, save_format=SaveFormat.XLSX) # 1 = XLSX 格式
Errors
RuntimeError: Proxy error(PyIOException): Exception was caused by unmanaged callback function error:
NotImplementedError
@zengweiyu,
我使用以下示例代码通过 .NET 的 Aspose.Cells for Python 测试了您的场景/案例,它运行良好,没有出现任何异常。我创建了一个工作簿,在工作表单元格中输入了一些值,将工作簿保存到字节 io 或流中。一切都运行良好。
import aspose.cells
from aspose.cells import Workbook, WorksheetCollection, Worksheet, CellsHelper, License, SaveFormat
import io
# Create a new workbook
workbook = Workbook()
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Add "Hello, World!" to cell A1
worksheet.cells.get("A1").put_value("Hello, World!")
# Create an io.BytesIO stream
stream = io.BytesIO()
# Save the workbook to the stream in Xlsx format
workbook.save(stream, SaveFormat.XLSX)
# Reset the stream position for further use
stream.seek(0)
# Optional: Save the stream content to a file to verify (for demonstration)
with open("e:\\test2\\HelloWorld.xlsx", "wb") as file:
file.write(stream.getvalue())
print("Excel workbook created and saved to stream successfully!")
files1.zip (6.7 KB)
您能否分享您的示例代码片段和模板 Excel 文件(如果有)以在我们这边重现该问题,我们会尽快检查。