Commit 56f12541 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander Trofimov

Revision: 52509

Author: Alexander.Trofimov
(1.0.0.92) - XlsxSerializerCom.dll
Добавил конвертацию из bin в csv
Revision: 52340
Author: Alexander.Trofimov
(1.0.0.91) - XlsxSerializerCom.dll
Добавил открытие CSV (сразу перегоняем его в наши структуры и возвращаем бинарник)
Для этого в опциях нужно передать xml-ку c типом файла, разделителем и кодировкой

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@52722 954022d7-b5bf-4e40-9824-e11837661b57
parent c6326a23
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
// temp , // temp ,
CString sTempTheme = CreateTheme(); CString sTempTheme = CreateTheme();
BinXlsxRW::BinaryFileReader oBinaryFileReader; BinXlsxRW::BinaryFileReader oBinaryFileReader;
oBinaryFileReader.ReadFile(sSrcFileName, sDstPath, sTempTheme, pOfficeDrawingConverter); oBinaryFileReader.ReadFile(sSrcFileName, sDstPath, sTempTheme, pOfficeDrawingConverter, CString(sXMLOptions));
::DeleteFile(sTempTheme); ::DeleteFile(sTempTheme);
RELEASEINTERFACE(pOfficeDrawingConverter); RELEASEINTERFACE(pOfficeDrawingConverter);
return S_OK; return S_OK;
...@@ -138,7 +138,7 @@ public: ...@@ -138,7 +138,7 @@ public:
pOfficeDrawingConverter->SetAdditionalParam(_T("FontPicker"), vt); pOfficeDrawingConverter->SetAdditionalParam(_T("FontPicker"), vt);
BinXlsxRW::BinaryFileWriter oBinaryFileWriter(m_oFontProcessor); BinXlsxRW::BinaryFileWriter oBinaryFileWriter(m_oFontProcessor);
oBinaryFileWriter.Open(CString(sSrcPath), CString(sDstFileName), pEmbeddedFontsManager, pOfficeDrawingConverter); oBinaryFileWriter.Open(CString(sSrcPath), CString(sDstFileName), pEmbeddedFontsManager, pOfficeDrawingConverter, CString(sXMLOptions));
RELEASEINTERFACE(pFontPicker); RELEASEINTERFACE(pFontPicker);
RELEASEINTERFACE(pOfficeDrawingConverter); RELEASEINTERFACE(pOfficeDrawingConverter);
......
#pragma once #pragma once
namespace BinXlsxRW namespace BinXlsxRW
{ {
const double g_dKoef_mm_to_pt = 72 / (2.54 * 10);
const double g_dKoef_mm_to_twips = 20 * g_dKoef_mm_to_pt;
const double g_dKoef_mm_to_emu = 36000;
const double g_dKoef_mm_to_eightpoint = 8 * g_dKoef_mm_to_pt;
const double g_dKoef_mm_to_pt = 72 / (2.54 * 10); const static TCHAR* g_sFormatSignature = _T("XLSY");
const double g_dKoef_mm_to_twips = 20 * g_dKoef_mm_to_pt; const int g_nFormatVersion = 2;
const double g_dKoef_mm_to_emu = 36000;
const double g_dKoef_mm_to_eightpoint = 8 * g_dKoef_mm_to_pt;
const static TCHAR* g_sFormatSignature = _T("XLSY"); namespace c_oFileTypes{enum c_oFileTypes
const int g_nFormatVersion = 2; {
XLSX = 1,
CSV = 2
};}
namespace c_oSerConstants{enum c_oSerConstants namespace c_oSerConstants{enum c_oSerConstants
......
...@@ -121,4 +121,45 @@ namespace SerializeCommon ...@@ -121,4 +121,45 @@ namespace SerializeCommon
aReplies.RemoveAll(); aReplies.RemoveAll();
} }
}; };
void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter)
{
result = BinXlsxRW::c_oFileTypes::XLSX;
nCodePage = CP_UTF8;
wcDelimiter = _T(',');
nullable<SimpleTypes::CUnsignedDecimalNumber<>> fileType;
nullable<SimpleTypes::CUnsignedDecimalNumber<>> codePage;
nullable<CString> delimiter;
// Read options
XmlUtils::CXmlLiteReader oReader;
if (TRUE != oReader.FromString(sXMLOptions) || TRUE != oReader.IsValid())
return;
oReader.ReadNextNode(); // XmlOptions
if (oReader.IsEmptyNode())
return;
int nCurDepth = oReader.GetDepth();
while(oReader.ReadNextSiblingNode(nCurDepth))
{
CWCharWrapper sName = oReader.GetName();
if (_T("fileOptions") == sName)
{
//
WritingElement_ReadAttributes_Start(oReader)
WritingElement_ReadAttributes_Read_if (oReader, _T("fileType"), fileType)
WritingElement_ReadAttributes_Read_else_if (oReader, _T("codePage"), codePage)
WritingElement_ReadAttributes_Read_else_if (oReader, _T("delimiter"), delimiter)
WritingElement_ReadAttributes_End(oReader)
result = (BYTE)fileType->GetValue();
nCodePage = (UINT)codePage->GetValue();
const CString& sDelimiter = delimiter.get();
if (0 < sDelimiter.GetLength())
wcDelimiter = sDelimiter.GetAt(0);
break;
}
}
return;
}
} }
\ No newline at end of file
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "../../ASCOfficePPTXFile/Editor/FontCutter.h" #include "../../ASCOfficePPTXFile/Editor/FontCutter.h"
#include "../../ASCOfficeDocxFile2/BinWriter/StreamUtils.h" #include "../../ASCOfficeDocxFile2/BinWriter/StreamUtils.h"
#include "../Writer/BinaryReader.h" #include "../Writer/BinaryReader.h"
#include "../Reader/CSVReader.h"
//#define DEFAULT_TABLE_STYLES //#define DEFAULT_TABLE_STYLES
...@@ -3744,7 +3745,8 @@ namespace BinXlsxRW { ...@@ -3744,7 +3745,8 @@ namespace BinXlsxRW {
{ {
RELEASEOBJECT(m_oBcw); RELEASEOBJECT(m_oBcw);
} }
void Open(CString& sInputDir, CString& sFileDst, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter) void Open(CString& sInputDir, CString& sFileDst, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager,
PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter, CString& sXMLOptions)
{ {
OOX::CPath path(sFileDst); OOX::CPath path(sFileDst);
// media // media
...@@ -3769,9 +3771,27 @@ namespace BinXlsxRW { ...@@ -3769,9 +3771,27 @@ namespace BinXlsxRW {
oBufferedStream.SetBuffer(&oBuffer); oBufferedStream.SetBuffer(&oBuffer);
m_oBcw = new BinaryCommonWriter(oBufferedStream); m_oBcw = new BinaryCommonWriter(oBufferedStream);
OOX::Spreadsheet::CXlsx oXlsx = OOX::Spreadsheet::CXlsx(OOX::CPath(sInputDir));
oXlsx.PrepareWorkbook(); // File Type
intoBindoc(oXlsx, oBufferedStream, pEmbeddedFontsManager, pOfficeDrawingConverter); BYTE fileType;
UINT nCodePage;
WCHAR wcDelimiter;
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, wcDelimiter);
OOX::Spreadsheet::CXlsx *pXlsx = NULL;
switch(fileType)
{
case BinXlsxRW::c_oFileTypes::CSV:
pXlsx = new OOX::Spreadsheet::CXlsx();
CSVReader::ReadFromCsvToXlsx(sInputDir, *pXlsx, nCodePage, wcDelimiter);
break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
pXlsx = new OOX::Spreadsheet::CXlsx(OOX::CPath(sInputDir));
break;
}
pXlsx->PrepareWorkbook();
intoBindoc(*pXlsx, oBufferedStream, pEmbeddedFontsManager, pOfficeDrawingConverter);
BYTE* pbBinBuffer = oBufferedStream.GetBuffer(); BYTE* pbBinBuffer = oBufferedStream.GetBuffer();
int nBinBufferLen = oBufferedStream.GetPosition(); int nBinBufferLen = oBufferedStream.GetPosition();
...@@ -3786,6 +3806,7 @@ namespace BinXlsxRW { ...@@ -3786,6 +3806,7 @@ namespace BinXlsxRW {
oFile.CloseFile(); oFile.CloseFile();
} }
RELEASEARRAYOBJECTS(pbBase64Buffer); RELEASEARRAYOBJECTS(pbBase64Buffer);
RELEASEOBJECT(pXlsx);
} }
private: private:
void intoBindoc(OOX::Spreadsheet::CXlsx &oXlsx, Streams::CBufferedStream &oBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter) void intoBindoc(OOX::Spreadsheet::CXlsx &oXlsx, Streams::CBufferedStream &oBufferedStream, NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter)
......
#pragma once
#include <stack>
namespace CSVReader
{
void AddCell(CString &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, BOOL bIsWrap)
{
while(!oDeleteChars.empty())
{
INT nIndex = oDeleteChars.top() - nStartCell;
sText.Delete(nIndex);
oDeleteChars.pop();
}
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
pCell->m_oType.Init();
WCHAR *pEndPtr;
LONG lValue = wcstol(sText, &pEndPtr, 10);
if (NULL != *pEndPtr)
{
//
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
pCell->m_oRichText.Init();
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
pText->m_sText = sText;
pCell->m_oRichText->m_arrItems.Add(pText);
}
else
{
//
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeNumber);
pCell->m_oValue.Init();
pCell->m_oValue->m_sText = sText;
}
if (bIsWrap)
{
// WrapStyle
pCell->m_oStyle.Init();
pCell->m_oStyle->SetValue(1);
}
pCell->m_oRef.Init();
pCell->m_oRef = OOX::Spreadsheet::CWorksheet::combineRef(nRow, nCol);
oRow.m_arrItems.Add(pCell);
}
void ReadFromCsvToXlsx(CString &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, CONST WCHAR wcDelimiter)
{
// Workbook
oXlsx.CreateWorkbook();
//
oXlsx.CreateStyles();
// wrap-
OOX::Spreadsheet::CStyles *pStyles = oXlsx.GetStyles();
pStyles->m_oCellXfs.Init();
pStyles->m_oCellXfs->m_oCount.Init();
pStyles->m_oCellXfs->m_oCount->SetValue(2);
// Normall default
OOX::Spreadsheet::CXfs* pXfs = NULL;
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
pXfs->m_oFillId.Init();
pXfs->m_oFillId->SetValue(0);
pXfs->m_oFontId.Init();
pXfs->m_oFontId->SetValue(0);
pXfs->m_oNumFmtId.Init();
pXfs->m_oNumFmtId->SetValue(0);
pStyles->m_oCellXfs->m_arrItems.Add(pXfs);
// Wrap style
pXfs = new OOX::Spreadsheet::CXfs();
pXfs->m_oBorderId.Init();
pXfs->m_oBorderId->SetValue(0);
pXfs->m_oFillId.Init();
pXfs->m_oFillId->SetValue(0);
pXfs->m_oFontId.Init();
pXfs->m_oFontId->SetValue(0);
pXfs->m_oNumFmtId.Init();
pXfs->m_oNumFmtId->SetValue(0);
pXfs->m_oApplyAlignment.Init();
pXfs->m_oApplyAlignment->SetValue(SimpleTypes::onoffTrue);
pXfs->m_oAligment.Init();
pXfs->m_oAligment->m_oWrapText.Init();
pXfs->m_oAligment->m_oWrapText->SetValue(SimpleTypes::onoffTrue);
pStyles->m_oCellXfs->m_arrItems.Add(pXfs);
CString sSheetRId = _T("rId1");
OOX::Spreadsheet::CWorksheet* pWorksheet = new OOX::Spreadsheet::CWorksheet();
pWorksheet->m_oSheetData.Init();
OOX::Spreadsheet::CSheet *pSheet = new OOX::Spreadsheet::CSheet();
pSheet->m_oRid.Init();
pSheet->m_oRid->SetValue(sSheetRId);
OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook();
pWorkbook->m_oSheets.Init();
pWorkbook->m_oSheets->m_arrItems.Add(pSheet);
MemoryMapping::CMappingFile oMappingFile = MemoryMapping::CMappingFile();
if(FALSE != oMappingFile.Open(sFileName))
{
long nFileSize = oMappingFile.GetSize();
LPCSTR pFileData = (LPCSTR)oMappingFile.GetData();
INT nSize = MultiByteToWideChar(nCodePage, 0, pFileData, nFileSize, NULL, 0);
WCHAR *pTemp = new WCHAR [nSize];
::ZeroMemory (pTemp, sizeof(WCHAR) * nSize);
MultiByteToWideChar (nCodePage, 0, pFileData, nFileSize, pTemp, nSize);
oMappingFile.Close();
CONST WCHAR wcNewLineN = _T('\n');
CONST WCHAR wcNewLineR = _T('\r');
CONST WCHAR wcQuote = _T('"');
CONST WCHAR wcTab = _T('\t');
BOOL bIsWrap = FALSE;
WCHAR wcCurrent;
INT nStartCell = 0;
std::stack<INT> oDeleteChars;
BOOL bInQuote = FALSE;
INT nIndexRow = 0;
INT nIndexCol = 0;
OOX::Spreadsheet::CRow *pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(nIndexRow + 1);
for (INT nIndex = 0; nIndex < nSize; ++nIndex)
{
wcCurrent = pTemp[nIndex];
if (wcDelimiter == wcCurrent)
{
if (bInQuote)
continue;
// New Cell
CString sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = FALSE;
nStartCell = nIndex + 1;
if (nStartCell == nSize)
{
pWorksheet->m_oSheetData->m_arrItems.Add(pRow);
pRow = NULL;
}
}
else if (wcNewLineN == wcCurrent || wcNewLineR == wcCurrent)
{
if (bInQuote)
{
// Wrap
bIsWrap = TRUE;
continue;
}
// New line
if (nStartCell != nIndex)
{
CString sCellText(pTemp + nStartCell, nIndex - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
bIsWrap = FALSE;
}
nStartCell = nIndex + 1;
pWorksheet->m_oSheetData->m_arrItems.Add(pRow);
pRow = new OOX::Spreadsheet::CRow();
pRow->m_oR.Init();
pRow->m_oR->SetValue(++nIndexRow + 1);
nIndexCol = 0;
}
else if (wcQuote == wcCurrent)
{
// Quote
if (FALSE == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
{
// ( )
bInQuote = !bInQuote;
nStartCell = nIndex + 1;
}
else if (TRUE == bInQuote)
{
//
oDeleteChars.push(nIndex);
// , (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex;
else
bInQuote = !bInQuote;
}
}
else if (wcTab == wcCurrent)
{
// delete tab if not delimiter
oDeleteChars.push(nIndex);
}
}
if (nStartCell != nSize)
{
// New line
CString sCellText(pTemp + nStartCell, nSize - nStartCell);
AddCell(sCellText, nStartCell, oDeleteChars, *pRow, nIndexRow, nIndexCol++, bIsWrap);
pWorksheet->m_oSheetData->m_arrItems.Add(pRow);
}
else
{
RELEASEOBJECT(pRow);
}
RELEASEARRAYOBJECTS(pTemp);
}
CAtlMap<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
arrWorksheets.SetAt(sSheetRId, pWorksheet);
}
}
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "../../ASCOfficeDocxFile2/BinWriter/StreamUtils.h" #include "../../ASCOfficeDocxFile2/BinWriter/StreamUtils.h"
#include "../Common/BinReaderWriterDefines.h" #include "../Common/BinReaderWriterDefines.h"
#include "../Common/Common.h" #include "../Common/Common.h"
#include "../Writer/CSVWriter.h"
namespace BinXlsxRW { namespace BinXlsxRW {
...@@ -3549,7 +3550,8 @@ namespace BinXlsxRW { ...@@ -3549,7 +3550,8 @@ namespace BinXlsxRW {
public: BinaryFileReader() public: BinaryFileReader()
{ {
} }
int ReadFile(CString sSrcFileName, CString sDstPath, CString& sTempTheme, PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter) int ReadFile(CString sSrcFileName, CString sDstPath, CString& sTempTheme,
PPTXFile::IAVSOfficeDrawingConverter* pOfficeDrawingConverter, CString& sXMLOptions)
{ {
bool bResultOk = false; bool bResultOk = false;
MemoryMapping::CMappingFile oMappingFile = MemoryMapping::CMappingFile(); MemoryMapping::CMappingFile oMappingFile = MemoryMapping::CMappingFile();
...@@ -3633,7 +3635,23 @@ namespace BinXlsxRW { ...@@ -3633,7 +3635,23 @@ namespace BinXlsxRW {
sAdditionalContentTypes = vt.bstrVal; sAdditionalContentTypes = vt.bstrVal;
} }
oXlsx.PrepareToWrite(); oXlsx.PrepareToWrite();
oXlsx.Write(sDstPath, sTempTheme, sAdditionalContentTypes);
// File Type
BYTE fileType;
UINT nCodePage;
WCHAR wcDelimiter;
SerializeCommon::ReadFileType(sXMLOptions, fileType, nCodePage, wcDelimiter);
switch(fileType)
{
case BinXlsxRW::c_oFileTypes::CSV:
CSVWriter::WriteFromXlsxToCsv(sDstPath, oXlsx, nCodePage, wcDelimiter);
break;
case BinXlsxRW::c_oFileTypes::XLSX:
default:
oXlsx.Write(sDstPath, sTempTheme, sAdditionalContentTypes);
break;
}
// //
for(int i = 0, length = aDeleteFiles.GetSize(); i < length; ++i) for(int i = 0, length = aDeleteFiles.GetSize(); i < length; ++i)
......
#pragma once
namespace CSVWriter
{
void WriteFile(CFile *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, CString &sWriteString, UINT &nCodePage, BOOL bIsEnd = FALSE)
{
if (NULL == pFile || NULL == pWriteBuffer)
return;
INT nCountChars = sWriteString.GetLength();
if (0 == nCountChars && !bIsEnd)
return;
CONST INT c_nSize = 1048576; // 1024 * 1024
CONST INT nSizeWchar = sizeof(WCHAR);
if (NULL == *pWriteBuffer)
{
*pWriteBuffer = new WCHAR[c_nSize];
::ZeroMemory(*pWriteBuffer, nSizeWchar * c_nSize);
nCurrentIndex = 0;
}
if (nCountChars + nCurrentIndex > c_nSize || bIsEnd)
{
// ,
INT nSize = WideCharToMultiByte(nCodePage, 0, *pWriteBuffer, nCurrentIndex, NULL, NULL, NULL, NULL);
CHAR *pString = new CHAR [nSize];
::ZeroMemory (pString, sizeof (CHAR) * nSize);
WideCharToMultiByte (CP_UTF8, 0, *pWriteBuffer, -1, pString, nSize, NULL, NULL);
pFile->WriteFile(pString, sizeof (CHAR) * nSize);
RELEASEARRAYOBJECTS(pString);
::ZeroMemory(*pWriteBuffer, nSizeWchar * c_nSize);
nCurrentIndex = 0;
}
if (!bIsEnd)
{
::CopyMemory(*pWriteBuffer + nCurrentIndex, sWriteString.GetBuffer(), nCountChars * nSizeWchar);
nCurrentIndex += nCountChars;
}
}
void WriteFromXlsxToCsv(CString &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, CONST WCHAR wcDelimiter)
{
CFile oFile;
oFile.CreateFileW(sFileDst);
LONG lActiveSheet = 0;
CString sSheetRId = _T("Sheet1"); // rId,
OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook();
if (NULL != pWorkbook)
{
// Get active sheet
if (pWorkbook->m_oBookViews.IsInit() && 0 < pWorkbook->m_oBookViews->m_arrItems.GetSize())
{
if (pWorkbook->m_oBookViews->m_arrItems[0]->m_oActiveTab.IsInit())
{
lActiveSheet = pWorkbook->m_oBookViews->m_arrItems[0]->m_oActiveTab->GetValue();
if (0 > lActiveSheet)
lActiveSheet = 0;
}
}
// Get active sheet rId
if (pWorkbook->m_oSheets.IsInit() && 0 <= pWorkbook->m_oSheets->m_arrItems.GetSize())
{
if (lActiveSheet <= pWorkbook->m_oSheets->m_arrItems.GetSize())
sSheetRId = pWorkbook->m_oSheets->m_arrItems[lActiveSheet]->m_oName.get2();
else
sSheetRId = pWorkbook->m_oSheets->m_arrItems[0]->m_oName.get2();
}
CAtlMap<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
CAtlMap<CString, OOX::Spreadsheet::CWorksheet*>::CPair* pPair = arrWorksheets.Lookup(sSheetRId);
if (NULL != pPair)
{
OOX::Spreadsheet::CWorksheet *pWorksheet = pPair->m_value;
if (NULL != pWorksheet && pWorksheet->m_oSheetData.IsInit())
{
OOX::Spreadsheet::CSharedStrings *pSharedStrings = oXlsx.GetSharedStrings();
CString sNewLineN = _T("\n");
CString sDelimiter = _T(""); sDelimiter += wcDelimiter;
CONST WCHAR wcQuote = _T('"');
CString sEscape = _T("\"\n");
sEscape += wcDelimiter;
INT nCurrentIndex = 0;
WCHAR *pWriteBuffer = NULL;
INT nRowCurrent = 1;
for (INT i = 0; i < pWorksheet->m_oSheetData->m_arrItems.GetSize(); ++i)
{
OOX::Spreadsheet::CRow *pRow = static_cast<OOX::Spreadsheet::CRow *>(pWorksheet->m_oSheetData->m_arrItems[i]);
INT nRow = pRow->m_oR.IsInit() ? pRow->m_oR->GetValue() : 0 == i ? nRowCurrent : nRowCurrent + 1;
while (nRow > nRowCurrent)
{
// Write new line
++nRowCurrent;
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
}
INT nColCurrent = 1;
for (INT j = 0; j < pRow->m_arrItems.GetSize(); ++j)
{
INT nRowTmp = 0;
INT nCol = 0;
if (!OOX::Spreadsheet::CWorksheet::parseRef(pRow->m_arrItems[j]->m_oRef.get2(), nRowTmp, nCol))
nCol = 0 == j ? nColCurrent : nColCurrent + 1;
while (nCol > nColCurrent)
{
// Write delimiter
++nColCurrent;
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDelimiter, nCodePage);
}
OOX::Spreadsheet::CCell *pCell = static_cast<OOX::Spreadsheet::CCell *>(pRow->m_arrItems[j]);
// Get cell value
CString sCellValue = _T("");
if (pCell->m_oValue.IsInit())
{
if (pCell->m_oType.IsInit() && SimpleTypes::Spreadsheet::celltypeNumber != pCell->m_oType->GetValue())
{
int nValue = _wtoi(pCell->m_oValue->ToString());
if (0 <= nValue && nValue < pSharedStrings->m_arrItems.GetSize())
{
OOX::Spreadsheet::CSi *pSi = static_cast<OOX::Spreadsheet::CSi *>(pSharedStrings->m_arrItems[nValue]);
if (NULL != pSi && pSi->m_arrItems.GetSize() > 0)
if(NULL != pSi && pSi->m_arrItems.GetSize() > 0)
{
OOX::Spreadsheet::WritingElement* pWe = pSi->m_arrItems[0];
if(OOX::Spreadsheet::et_t == pWe->getType())
{
OOX::Spreadsheet::CText* pText = static_cast<OOX::Spreadsheet::CText*>(pWe);
sCellValue = pText->m_sText;
}
}
}
}
else
{
sCellValue = pCell->m_oValue->ToString();
}
}
// Escape cell value
if (-1 != sCellValue.FindOneOf(sEscape))
{
sCellValue.Replace(_T("\""), _T("\"\""));
sCellValue = wcQuote + sCellValue + wcQuote;
}
// Write cell value
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sCellValue, nCodePage);
}
}
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, TRUE);
RELEASEARRAYOBJECTS(pWriteBuffer);
}
}
}
oFile.CloseFile();
}
}
\ No newline at end of file
...@@ -270,6 +270,10 @@ ...@@ -270,6 +270,10 @@
RelativePath=".\Reader\BinaryWriter.h" RelativePath=".\Reader\BinaryWriter.h"
> >
</File> </File>
<File
RelativePath=".\Reader\CSVReader.h"
>
</File>
<File <File
RelativePath=".\Reader\FontProcessor.h" RelativePath=".\Reader\FontProcessor.h"
> >
...@@ -302,6 +306,10 @@ ...@@ -302,6 +306,10 @@
RelativePath=".\Writer\BinaryReader.h" RelativePath=".\Writer\BinaryReader.h"
> >
</File> </File>
<File
RelativePath=".\Writer\CSVWriter.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
//1 //1
//0 //0
//0 //0
//91 //92
#define INTVER 1,0,0,91 #define INTVER 1,0,0,92
#define STRVER "1,0,0,91\0" #define STRVER "1,0,0,92\0"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment