• 大小: 36KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: 其他
  • 标签:

资源简介

开源basic_excel存在读excel文件时load异常,原因是对其中work表中WORKBOOK_GLOBALS的case CODE::SST组装存在bug,SST中存放全局的stting信息,当其长度超过8224时就需要拆分记录,新的记录标识位为[CODE::CONTINUE],因此,读时需要组装; 这折分有几种规则,1、前一个字符串还没有完时,后续的新recode开头只有1个字节的unicode标识;2、前一个字符串完整时,那后续新recode正常开头了; 具体的修改见代码;

资源截图

代码片段和文件信息


#include “basic_excel.hpp“
#include “assert.h“

namespace YCompoundFiles
{
/********************************** Start of Class Block *************************************/
// PURPOSE: Manage a file by treating it as blocks of data of a certain size.
Block::Block() : 
blockSize_(512) fileSize_(0) indexEnd_(0)
filename_(0) {}

bool Block::Create(const wchar_t* filename)
// PURPOSE: Create a new block file and open it.
// PURPOSE: If file is present truncate it and then open it.
// PROMISE: Return true if file is successfully created and opened false if otherwise.
{
// Create new file
size_t filenameLength = wcslen(filename);
char* name = new char[filenameLength+1];
wcstombs(name filename filenameLength);
name[filenameLength] = 0;

file_.open(name ios_base::out | ios_base::trunc);
file_.close();
file_.clear();

// Open the file
bool ret = this->Open(filename);
delete[] name;
return ret;
}

bool Block::Open(const wchar_t* filename ios_base::openmode mode)
// PURPOSE: Open an existing block file.
// PROMISE: Return true if file is successfully opened false if otherwise.
{
// Open existing file for reading or writing or both
size_t filenameLength = wcslen(filename);
filename_.resize(filenameLength+1 0);
wcstombs(&*(filename_.begin()) filename filenameLength);

file_.open(&*(filename_.begin()) mode | ios_base::binary);
if (!file_.is_open()) return false;

mode_ = mode;

// Calculate filesize
if (mode & ios_base::in)
{
file_.seekg(0 ios_base::end);
fileSize_ = file_.tellg();
}
else if (mode & ios_base::out)
{
file_.seekp(0 ios_base::end);
fileSize_ = file_.tellp();
}
else
{
this->Close();
return false;
}

// Calculate last index + 1
indexEnd_ = fileSize_/blockSize_ + (fileSize_ % blockSize_ ? 1 : 0);
return true;
}

bool Block::Close()
// PURPOSE: Close the opened block file.
// PROMISE: Return true if file is successfully closed false if otherwise.
{
file_.close();
file_.clear();
filename_.clear(); 
fileSize_ = 0; 
indexEnd_ = 0; 
blockSize_ = 512;
return !file_.is_open();
}

bool Block::IsOpen()
// PURPOSE: Check if the block file is still opened.
// PROMISE: Return true if file is still opened false if otherwise.
{
return file_.is_open();
}

bool Block::Read(size_t index char* block)
// PURPOSE: Read a block of data from the opened file at the index position.
// EXPLAIN: index is from [0..].
// PROMISE: Return true if data are successfully read false if otherwise.
{
if (!(mode_ & ios_base::in)) return false;
if (index < indexEnd_)
{
file_.seekg(index * blockSize_);
file_.read(block blockSize_);
return !file_.fail();
}
else return false;
}

bool Block::Write(size_t index const char* block)
// PURPOSE: Write a block of data to the opened file at the index position.
// EXPLAIN: index is from [0..].
// PROMISE: Return true if data are successfully written false

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     185821  2012-06-10 22:43  basic_excel\basic_excel.cpp

     文件      46476  2012-06-10 22:27  basic_excel\basic_excel.hpp

     目录          0  2012-06-10 22:43  basic_excel

----------- ---------  ---------- -----  ----

               232297                    3


评论

共有 条评论

相关资源