| | |
Convert C++ to VB.Net
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
I found some code on the web a while back. But I don't know who wrote it.
The code below looks for worksheet names in a excel file. I am not familiar with C++ (and do little to nothing with binary files). Can someone help me convert the code below from C++ to VB.net? Thank you in advance.
trf
The code below looks for worksheet names in a excel file. I am not familiar with C++ (and do little to nothing with binary files). Can someone help me convert the code below from C++ to VB.net? Thank you in advance.
trf
C++ Syntax (Toggle Plain Text)
IStorage *pStorage = 0; HRESULT hResult = ::StgOpenStorage(L"C:\\MyExcel.xls", NULL, STGM_READ |STGM_SHARE_DENY_WRITE, NULL, 0, &pStorage); IStream *pStream = 0; hResult = pStorage->OpenStream(L"Workbook", NULL, STGM_READ |STGM_SHARE_EXCLUSIVE, 0, &pStream); char buf[32000]; DWORD dwRead = 0; short id = 0, len = 0; while (1) { hResult = pStream->Read(&id, 2, &dwRead); if( (FAILED(hResult)) || (dwRead != 2) ) break; hResult = pStream->Read(&len, 2, &dwRead); if( (FAILED(hResult)) || dwRead != 2 || ((id == 0) && (len == 0)) ) break; if( (id & 0x00FF) == 0x85 ) { pStream->Read(buf, len, &dwRead); buf[len] = 0; cout << buf+8 << endl; continue; } if(len > sizeof(buf)) len = sizeof(buf); pStream->Read(buf, (long)len, &dwRead); if((DWORD)len != dwRead) break; }
You should forget about converting C++ to VB.NET and look for something originally in .NET. It's a lot easier to use the excel library or ADO.NET than to hack the file format as a binary stream.
There are a lot of threads on reading and writing excel on the vb.net forum, go check those out.
There are a lot of threads on reading and writing excel on the vb.net forum, go check those out. The truth does not change according to our ability to stomach it.
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
Sorry in advance for the length.
I hear you here. I find myself in a tight spot and there isn’t much I can do. I use the .Net Report Viewer control to render Excel 97 Biff8 files. Rendering is a nice side feature of the control (the main being report viewing). I need to create Biff8 files from code running on a server. Since my code runs on a server, Excel automation is out (too many instances of it will need to run and it will crash). I could look a buying something but my employer isn’t big on that. Besides I have something working perfectly. Perfectly that is except the output doesn’t have the gridlines on. Its true BIFF8 (which is a requirement) but with the gridlines off there has been too much confusion from the LOB. So I’ve been told, get those grids on.
I’ve looked off-and-on for weeks for a solution, but have found nothing. All I could think to do at this point was to pull a document explaining the file format (http://sc.openoffice.org/excelfileformat.pdf) and try to write the updates to the files myself. It didn’t sound too bad until I tried it (ha).
So then I read up on the Biff8 for Excel, found it was an OLE2 Binary file, and went looking for anything related to updating that. Surprisingly I found some C++ articles at least talking about it. Then I found this, which appears to read through an Excel file. I figured this was at least a start.
Anyway given a more detailed explanation of my situation and why I find myself needing to reverse engineer the above C++ example, do you think anyone might be able to help me here? In the interim I’m using ADO to create basic XLS files but I will only be able to get by on that so long.
Thanks for any ideas.
I hear you here. I find myself in a tight spot and there isn’t much I can do. I use the .Net Report Viewer control to render Excel 97 Biff8 files. Rendering is a nice side feature of the control (the main being report viewing). I need to create Biff8 files from code running on a server. Since my code runs on a server, Excel automation is out (too many instances of it will need to run and it will crash). I could look a buying something but my employer isn’t big on that. Besides I have something working perfectly. Perfectly that is except the output doesn’t have the gridlines on. Its true BIFF8 (which is a requirement) but with the gridlines off there has been too much confusion from the LOB. So I’ve been told, get those grids on.
I’ve looked off-and-on for weeks for a solution, but have found nothing. All I could think to do at this point was to pull a document explaining the file format (http://sc.openoffice.org/excelfileformat.pdf) and try to write the updates to the files myself. It didn’t sound too bad until I tried it (ha).
So then I read up on the Biff8 for Excel, found it was an OLE2 Binary file, and went looking for anything related to updating that. Surprisingly I found some C++ articles at least talking about it. Then I found this, which appears to read through an Excel file. I figured this was at least a start.
Anyway given a more detailed explanation of my situation and why I find myself needing to reverse engineer the above C++ example, do you think anyone might be able to help me here? In the interim I’m using ADO to create basic XLS files but I will only be able to get by on that so long.
Thanks for any ideas.
![]() |
Similar Threads
- how to convert vb.net project into exe file (VB.NET)
- Simple ASP.Net Login Page using C# (C#)
- .NET vs VB6 - differences? (VB.NET)
- PHP vs ASP... the big ShOwdOwN (IT Professionals' Lounge)
- To display an icon in a datagrid (VB.NET)
- how to convert C++ to VB (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: Test DataBase Application
- Next Thread: can't see output although it has no error while compiling
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





