使用 OLEDB 操作 Excel 文件,使用文件流而不是物理文件

发布于 2024-07-15 20:08:41 字数 158 浏览 6 评论 0原文

早些时候,我通过 Microsoft.Jet.OLEDB.4.0 读取位于文件系统上的 excel 文件,并且工作正常,但现在我的客户告诉我,将 excel 文件作为 BLOB 列放入数据库表中,并从该列读取该文件并通过直接操作该内存字符串来隐藏一个工作簿。

请帮我解决这个问题吗?

Earlier I was reading excel file located on file system through Microsoft.Jet.OLEDB.4.0, and that was working fine, But now my client has told me that place excel file into a database table as BLOB column and read that file from that column and hide one workbook by manipulating that memory string directly.

Please help me out from this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2024-07-22 20:08:41

使用 BLOB 内容创建一个临时文件,并在完成后替换 BLOB。

string fileName = Path.GetTempFileName();
using (var stream = File.OpenWrite(fileName))
  stream.Write(blobContents);

// open excel with oledb
// and do your processing

using (var stream = File.OpenRead(fileName))
{
   var buffer = new byte[stream.Length];
   stream.Read(buffer, 0, stream.Length);

   //save blob
}

Create a temp with the BLOB contents and replace the BLOB when done.

string fileName = Path.GetTempFileName();
using (var stream = File.OpenWrite(fileName))
  stream.Write(blobContents);

// open excel with oledb
// and do your processing

using (var stream = File.OpenRead(fileName))
{
   var buffer = new byte[stream.Length];
   stream.Read(buffer, 0, stream.Length);

   //save blob
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文