Tag: visual c ++

如何从excel中获得unicodestring

嗨,我正在使用ExcelFormat库从一个Excel文件(.xls)中提取一些内容,它包含一些Unicode字符这里是代码 BasicExcel xls(from); XLSFormatManager fmt_mgr(xls); BasicExcelWorksheet* sheet = xls.GetWorksheet(0); CellFormat fmt_general(fmt_mgr); fmt_general.set_format_string("0.000"); for (int y = 0; y<2; ++y) { for (int x = 0; x<2; ++x) { BasicExcelCell* cell = sheet->Cell(y, x); cout << sheet->Cell(y, x)->GetWString(); CellFormat fmt(fmt_mgr, cell); const Workbook::Font& font = fmt_mgr.get_font(fmt); string font_name = stringFromSmallString(font.name_); const wstring& fmt_string = fmt.get_format_string(); cell->SetFormat(fmt_general); […]

如何获取MSVC中的成员函数指针?

我不会深入Excel的细节,我基本上从这个例子的代码: C ++应用程序自动化Excel(CppAutomateExcel) solution1.cpp 所以我已经在MSVC中试过这个代码,它编译: class foo { public: virtual void bar(){} }; int main() { void (foo::*p)() = &foo::bar; } 但是在Excel中捕获移动函数地址的类似代码不起作用: int main() { Excel::_ApplicationPtr spXlApp; HRESULT hr = spXlApp.CreateInstance(__uuidof(Excel::Application)); Excel::WorkbooksPtr spXlBooks = spXlApp->Workbooks; Excel::_WorkbookPtr spXlBook = spXlBooks->Add(); Excel::_WorksheetPtr spXlSheet = spXlBook->ActiveSheet; HRESULT(Excel::_Worksheet::*pMove)(…) = &spXlSheet->Excel::_Worksheet::Move; <… irrelevant code …> return 0; } 这有以下编译器错误: 错误C2276:'&':绑定成员函数expression式的非法操作 […]

该字段太小,无法接受写入excel时尝试添加的数据量

我得到这个错误,当我写Cstring数据到VC ++ xls文件。 其实我正在从同一个文件的不同列读取数据。 做了一些操作之后,我把它放回到同一个文件的不同列中,对于接受的小数据。 一旦大尺寸的消息来了,它是抛出一个怀疑和打破。 代码function粘贴如下: void CLoadOcxDlg::read(std::string excelFile, int sheetIndex, bool header, std::string csvFile) { clock_t t1 = clock(); std::cout << "reading " << excelFile; if(FAILED(::CoInitialize(NULL))) return; _RecordsetPtr pSchema = NULL; _RecordsetPtr pRec = NULL; int cellCount = 0; try { _bstr_t connStr(makeConnStr(excelFile, header).c_str()); TESTHR(pRec.CreateInstance(__uuidof(Recordset))); TESTHR(pRec->Open(sqlSelectSheet(connStr, sheetIndex).c_str(), connStr, adOpenStatic, adLockOptimistic, adCmdText)); //TESTHR(pRec->Open(sqlSelectSheet(connStr, sheetIndex).c_str(), […]

C ++ / CLI如何使用相对path打开Excel文件?

我对C ++ / CLI相当陌生,而且在打开Excel文件时遇到了麻烦。 这是我的下面的代码示例。 #using <system.dll> using namespace System; using namespace Microsoft::Office::Interop::Excel; String ^filename = gcnew String(L"Test.xlsx"); try { Application^ exapp = gcnew ApplicationClass(); Workbook^ wb = exapp->Workbooks->Open(filename, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing); Worksheet^ exws = safe_cast<Worksheet^>(exapp->ActiveSheet); exws->Cells[1, 1] = "Hello world"; return true; Console::WriteLine("File […]

C ++未处理的exception – 堆已损坏

我正在苦于间歇性的C ++应用程序崩溃。 我不是一个C ++程序员,但我负责解决这个问题,所以非常希望你能帮助我。 通常应用程序运行良好,然后有时会崩溃,例外。 当从运行exe进入debugging时,高亮显示的代码行似乎是错误的 – 请参阅第一个屏幕截图。 我在第二个屏幕截图中扩大了一些当地人。 这行代码调用一个函数“ClearVariant”代码如下这个函数: /* * ClearVariant * * Zeros a variant structure without regard to current contents */ void CXLAutomation::ClearVariant(VARIANTARG *pvarg) { pvarg->vt = VT_EMPTY; pvarg->wReserved1 = 0; pvarg->wReserved2 = 0; pvarg->wReserved3 = 0; pvarg->lVal = 0; } 整个cpp文件在post的末尾。 OpenExcelFile是导致这个问题的函数 – 就像你可以从屏幕截图中的调用栈一样。 // XLAutomation.cpp: implementation of the CXLAutomation […]