gpt4 book ai didi

c++ - 该字段太小,无法接受您在写入 Excel 时尝试添加的数据量

转载 作者:行者123 更新时间:2023-11-28 06:38:54 24 4
gpt4 key购买 nike

当我在 VC++ 中将 Cstring 数据写入 xls 文件时出现此错误。实际上我正在读取同一文件中不同列的数据。在做了一些操作后,我将它放回同一个文件的不同列中,对于它已接受的小数据。一旦较大的消息到来,它就会抛出异常并中断。

函数代码贴在下面:

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(), connStr, adOpenKeyset, adLockUnspecified, adCmdText));

std::ofstream stream(csvFile.c_str());

while(!pRec->adoEOF)
{
for(long i = 8; i < pRec->Fields->GetCount(); )//++i)
{
CString Label = pRec->Fields->GetItem("LABEL/SMI")->Value;

if((Label == "AA") || (Label == "A6") || (Label == "BA") || (Label == "B6"))
{

CString str = pRec->Fields->GetItem(i + 8)->Value;
//_variant_t v = pRec->Fields->GetItem(i+8)->Value;
//if((v.vt == VT_R8) || (v.vt == VT_BSTR))
CString baseString = "/";

{

if(str.GetLength())
{
int iCount = 0;

iCount = str.ReverseFind('/');
//Removing the Message part before '/'
str.Delete(0,iCount+1);
//CString baseString = "/";
baseString.Append(Label);
baseString.Append(" ");
baseString.Append(str);
baseString.Delete(baseString.GetLength() - 5,baseString.GetLength());
//pRec->Fields->GetItem(i + 9)->Value = _variant_t(baseString);
}



m_strDecodedMesg = m_ctrlDecoder.DecodeMessage(baseString);

long length = m_strDecodedMesg.GetLength();

m_strDecodedMesg.Insert(0,'"');
m_strDecodedMesg.Insert((m_strDecodedMesg.GetLength()+1),'"');
stream <<m_strDecodedMesg

**pRec-="">
Fields->GetItem("DECODED_MESSAGE")->Value = _variant_t(m_strDecodedMesg);**

pRec->Fields->GetItem("LENGTH")->Value = _variant_t(length);

DataTypeEnum ctype;
ctype = pRec->Fields->GetItem("DECODED_MESSAGE")->GetType();

TESTHR(pRec->Update());

}
++cellCount;
}
else
{

stream << _T("\" \"");
}
stream << std::endl;
pRec->MoveNext();
/*if(pRec->adoEOF)
MessageBox("Decoding is Completed");*/
}

}


}
catch(_com_error &e)
{
_bstr_t bstrDescription(e.Description());
CharToOem(bstrDescription, bstrDescription);
std::cout << bstrDescription << std::endl;
}
//if(connStr->State == adStateOpen) connStr->Close();
::CoUninitialize();


clock_t t2 = clock();
double t = (double)(t2 - t1) / CLOCKS_PER_SEC;
std::cout << ": " << t << " sec; " << cellCount / t << " cells/sec" << "; see " << csvFile << std::endl;
}

最佳答案

如果你准备好几样东西,问题就会解决:

  1. 删除您更改的行(使用正确的方式,意味着正确的 sql 查询,或者可能是另一种类似的方法,Excel 单元格在顶部,我们可以看到,在后台是一个数据库,你知道... 表名是工作表名称 ...等等 ,, 这个 ADO,Microsoft ... )
  2. 之后,您可以使用字段名称重新排列行,这对您来说很有趣,请保持字段的类型:)

我刚刚完成了一项与添加到生物计量 access_control 软件类似的任务,使用的功能(您可以使用):

    pCmd->Execute(NULL, NULL, adCmdText);
TESTHR(pRec.CreateInstance(__uuidof(Recordset)));
pRec->Open("SELECT * FROM MySheet", _variant_t((IDispatch*)pCon), adOpenKeyset, adLockOptimistic, adCmdText);

TESTHR(pRec->Update());
TESTHR(pRec->Close());
}
catch(_com_error &e)
{
_bstr_t bstrDescription(e.Description());
CharToOem(bstrDescription, bstrDescription);
std::cout << bstrDescription << std::endl;
}

这门课非常具体,而且过于复杂,仅适用于时不时的任务。我记得 Kraig Bruckshmidt(OLE 和 COM 畅销书的作者)在组件对象模型中对 David Kruglinski 说的话:“大卫,当我开始使用 COM 时,头六个月对我来说就像一团迷雾。”

不可能一下子解释清楚。如果您有任何疑问或需要建议,我很乐意。

关于c++ - 该字段太小,无法接受您在写入 Excel 时尝试添加的数据量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26316953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com