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

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.

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.

You can buid a DLL and call from your .NET program.

Edit: removed

cv::Mat ResultImage11 = cv::Mat::zeros(resu_textpic3.size(), CV_8UC1);
        cv::drawContours(ResultImage11, contoursTarget, -1, Scalar(255, 255, 255), 1, 8, Mat());

        //cv::RotatedRect ellipse;
        int rid1 = 480;
        int rid2 = 600;
        //去除干扰
        vector<vector<Point>> filteredContours;
        for (int i = 0; i < contoursTarget.size(); i++) {
            for (size_t j = 0; j < contoursTarget[i].size(); j++)
            {
                double con_distance = calculateDistance(contoursTarget[i][j], R_cir);
                if (rid1 < con_distance && con_distance < rid2) {
                    filteredContours.push_back(contoursTarget[i]);
                }
            }
        }
        vector<vector<Point>> filteredContours1;
        for (int i = 0; i < filteredContours.size(); i++) {

            double area = cv::contourArea(filteredContours[i]);
            if (area >= 1) {
                filteredContours1.push_back(filteredContours[i]);
            }
        }
commented: Are you sure that 15 years later is a good idea? -4
commented: Waaay too late, and not even close to being on-topic -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.