![](/img/trans.png)
[英]GCP storage - read data from mongo db and write it into to file GCP bucket
[英]How read XLS file from gcp bucket
我有桶XLS
文件,我必須提取文件並讀取流中的數據並處理數據。 我使用了CSV
文件,這是我的代碼:
try (ReadChannel reader = storage.reader(bucketName, fileName)) {
ByteBuffer bytes = ByteBuffer.allocate(BUFFER_SIZE);
while (reader.read(bytes) > 0) {
bytes.flip();
// outChannel.write(bytes);
set(new String(bytes.array(), "UTF-8"), fileName);
bytes.clear();
}
}
我想這可能就是你要找的。 GCS 輸入通道
GcsService gcsService = GcsServiceFactory.createGcsService();
GcsFilename fileName = new GcsFilename("TestBucket", "Test1.xlsx");
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
InputStream inputStream = Channels.newInputStream(readChannel);
我還發現了一個可能對您有所幫助的有趣解決方法,在這個答案中,您有一段代碼可以將所有 excel 文件轉換為 CSV,以便您可以正常操作它們。
編輯:錯誤在那里,因為它沒有被初始化。 看看我的代碼編輯。
在你的情況下,據我所知,你可能需要使用“ OutputChannel ”而不是“InputChannel”,但它是相同的概念。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.