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

add ASCOfficeDocxFile2Lib.pro; сохранение csv не учитывалась выбранная...

add ASCOfficeDocxFile2Lib.pro; сохранение csv не учитывалась выбранная кодировка(всегда utf8);несколько memory leak;

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@59144 954022d7-b5bf-4e40-9824-e11837661b57
parent c3f957be
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
#include "../../ASCOfficePPTXFile/Editor/FontPicker.h" #include "../../ASCOfficePPTXFile/Editor/FontPicker.h"
#include "../../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h" #include "../../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h"
#ifndef _WIN32
#include "../../DesktopEditor/common/Types.h"
#endif
int BinDocxRW::g_nCurFormatVersion = 0; int BinDocxRW::g_nCurFormatVersion = 0;
BinDocxRW::CDocxSerializer::CDocxSerializer() BinDocxRW::CDocxSerializer::CDocxSerializer()
...@@ -65,8 +61,6 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C ...@@ -65,8 +61,6 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C
oDrawingConverter.SetFontManager(pFontManager); oDrawingConverter.SetFontManager(pFontManager);
NSBinPptxRW::CBinaryFileWriter& oBufferedStream = *oDrawingConverter.m_pBinaryWriter; NSBinPptxRW::CBinaryFileWriter& oBufferedStream = *oDrawingConverter.m_pBinaryWriter;
#ifdef _WIN32
NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager = NULL; NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager = NULL;
if(false == m_sEmbeddedFontsDir.IsEmpty()) if(false == m_sEmbeddedFontsDir.IsEmpty())
{ {
...@@ -92,7 +86,6 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C ...@@ -92,7 +86,6 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C
ParamsWriter oParamsWriter(oBufferedStream, fp, &oDrawingConverter, pEmbeddedFontsManager); ParamsWriter oParamsWriter(oBufferedStream, fp, &oDrawingConverter, pEmbeddedFontsManager);
m_oBinaryFileWriter = new BinaryFileWriter(oParamsWriter); m_oBinaryFileWriter = new BinaryFileWriter(oParamsWriter);
m_oBinaryFileWriter->intoBindoc(sDstPath); m_oBinaryFileWriter->intoBindoc(sDstPath);
#endif
BYTE* pbBinBuffer = oBufferedStream.GetBuffer(); BYTE* pbBinBuffer = oBufferedStream.GetBuffer();
int nBinBufferLen = oBufferedStream.GetPosition(); int nBinBufferLen = oBufferedStream.GetPosition();
...@@ -115,6 +108,7 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C ...@@ -115,6 +108,7 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C
oFile.WriteFile(pbBase64Buffer, nBase64BufferLen); oFile.WriteFile(pbBase64Buffer, nBase64BufferLen);
oFile.CloseFile(); oFile.CloseFile();
} }
RELEASEARRAYOBJECTS(pbBase64Buffer);
} }
RELEASEOBJECT(m_oBinaryFileWriter); RELEASEOBJECT(m_oBinaryFileWriter);
RELEASEOBJECT(pFontPicker); RELEASEOBJECT(pFontPicker);
......
#-------------------------------------------------
#
# Project created by QtCreator 2014-10-10T14:24:04
#
#-------------------------------------------------
QT -= core gui
TARGET = ASCOfficeDocxFile2Lib
TEMPLATE = lib
CONFIG += staticlib
QMAKE_CXXFLAGS += -std=c++0x -Wall -Wno-ignored-qualifiers -g
DEFINES += UNICODE \
_UNICODE \
LINUX \
_LINUX_QT \
NODOCX \
_USE_XMLLITE_READER_ \
USE_LITE_READER \
USE_ATL_CSTRING \
USE_AVSOFFICESTUDIO_XMLUTILS \
SOLUTION_ASCOFFICEDOCXFILE2 \
DISABLE_FILE_DOWNLOADER \
_USE_LIBXML2_READER_ \
LIBXML_READER_ENABLED
INCLUDEPATH += \
../../DesktopEditor/freetype-2.5.2/include \
../../Common/DocxFormat/Source/XML/libxml2/XML/include
SOURCES += ../DocWrapper/DocxSerializer.cpp \
../DocWrapper/FontProcessor.cpp \
../DocWrapper/XlsxSerializer.cpp \
../../XlsxSerializerCom/Common/Common.cpp \
../../XlsxSerializerCom/Reader/ChartFromToBinary.cpp \
../../XlsxSerializerCom/Reader/CommonWriter.cpp \
../../XlsxSerializerCom/Reader/CSVReader.cpp \
../../XlsxSerializerCom/Writer/CSVWriter.cpp
HEADERS += ../DocWrapper/DocxSerializer.h \
../DocWrapper/FontProcessor.h \
../DocWrapper/XlsxSerializer.h \
../BinReader/ChartWriter.h \
../BinReader/CommentsWriter.h \
../BinReader/ContentTypesWriter.h \
../BinReader/DocumentRelsWriter.h \
../BinReader/DocumentWriter.h \
../BinReader/FileWriter.h \
../BinReader/fontTableWriter.h \
../BinReader/HeaderFooterWriter.h \
../BinReader/MediaWriter.h \
../BinReader/NumberingWriter.h \
../BinReader/ReaderClasses.h \
../BinReader/Readers.h \
../BinReader/SettingWriter.h \
../BinReader/StylesWriter.h \
../BinWriter/BinEquationWriter.h \
../BinWriter/BinReaderWriterDefines.h \
../BinWriter/BinWriters.h \
../../XlsxSerializerCom/Common/BinReaderWriterDefines.h \
../../XlsxSerializerCom/Common/Common.h \
../../XlsxSerializerCom/Reader/BinaryWriter.h \
../../XlsxSerializerCom/Reader/ChartFromToBinary.h \
../../XlsxSerializerCom/Reader/CommonWriter.h \
../../XlsxSerializerCom/Reader/CSVReader.h \
../../XlsxSerializerCom/Writer/BinaryCommonReader.h \
../../XlsxSerializerCom/Writer/BinaryReader.h \
../../XlsxSerializerCom/Writer/CSVWriter.h
unix {
target.path = /usr/lib
INSTALLS += target
}
This diff is collapsed.
...@@ -690,7 +690,7 @@ namespace NSBinPptxRW ...@@ -690,7 +690,7 @@ namespace NSBinPptxRW
//strDst64.SetString(pbBase64Buffer, nBase64BufferLen); //strDst64.SetString(pbBase64Buffer, nBase64BufferLen);
strDst64 = pbBase64Buffer; strDst64 = pbBase64Buffer;
} }
RELEASEARRAYOBJECTS(pbBase64Buffer);
RELEASEARRAYOBJECTS(pBuffer); RELEASEARRAYOBJECTS(pBuffer);
oFile.CloseFile(); oFile.CloseFile();
......
...@@ -282,7 +282,7 @@ namespace XmlUtils ...@@ -282,7 +282,7 @@ namespace XmlUtils
reader = NULL; reader = NULL;
m_pStream = NULL; m_pStream = NULL;
} }
~CXmlLiteReader() virtual ~CXmlLiteReader()
{ {
if (NULL != m_pStream) if (NULL != m_pStream)
delete []m_pStream; delete []m_pStream;
......
...@@ -4,13 +4,20 @@ ...@@ -4,13 +4,20 @@
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h" #include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
#include "../../Common/Base64.h" #include "../../Common/Base64.h"
#include "../../DesktopEditor/common/Types.h" #include "../../DesktopEditor/common/Types.h"
#ifndef DISABLE_FILE_DOWNLOADER
#include "../../ASCOfficeDocxFile2/BinReader/FileDownloader.h" #include "../../ASCOfficeDocxFile2/BinReader/FileDownloader.h"
#endif
#include "../../DesktopEditor/common/file.h" #include "../../DesktopEditor/common/file.h"
#ifndef CP_UTF8
#define CP_UTF8 65001
#endif
namespace SerializeCommon namespace SerializeCommon
{ {
CString DownloadImage(const CString& strFile) CString DownloadImage(const CString& strFile)
{ {
#ifndef DISABLE_FILE_DOWNLOADER
CFileDownloader oDownloader(strFile, FALSE); CFileDownloader oDownloader(strFile, FALSE);
oDownloader.Start( 1 ); oDownloader.Start( 1 );
while ( oDownloader.IsRunned() ) while ( oDownloader.IsRunned() )
...@@ -23,16 +30,17 @@ namespace SerializeCommon ...@@ -23,16 +30,17 @@ namespace SerializeCommon
strFileName = oDownloader.GetFilePath(); strFileName = oDownloader.GetFilePath();
} }
return strFileName; return strFileName;
#else
return L"";
#endif
} }
VOID convertBase64ToImage (NSFile::CFileBinary& oFile, CString &pBase64) VOID convertBase64ToImage (NSFile::CFileBinary& oFile, CString &pBase64)
{ {
INT nUTF8Len = WideCharToMultiByte (CP_UTF8, 0, pBase64, pBase64.GetLength (), NULL, NULL, NULL, NULL); BYTE* pUtf8 = NULL;
CHAR *pUTF8String = new CHAR [nUTF8Len + 1]; long nUtf8Size;
memset(pUTF8String, 0, sizeof (CHAR) * (nUTF8Len + 1)); NSFile::CUtf8Converter::GetUtf8StringFromUnicode(pBase64.GetString(), pBase64.GetLength(), pUtf8, nUtf8Size);
CStringA sUnicode((char*)pUtf8, nUtf8Size);
WideCharToMultiByte (CP_UTF8, 0, pBase64, -1, pUTF8String, nUTF8Len, NULL, NULL); RELEASEARRAYOBJECTS(pUtf8);
CStringA sUnicode; sUnicode = pUTF8String;
delete[] pUTF8String;
// "data:image/jpg;base64," // "data:image/jpg;base64,"
int nShift = 0; int nShift = 0;
...@@ -60,14 +68,10 @@ namespace SerializeCommon ...@@ -60,14 +68,10 @@ namespace SerializeCommon
} }
CString changeExtention(const CString& sSourcePath, const CString& sTargetExt) CString changeExtention(const CString& sSourcePath, const CString& sTargetExt)
{ {
wchar_t path_buffer[_MAX_PATH]; int nIndex = sSourcePath.ReverseFind('.');
wchar_t drive[_MAX_DRIVE]; if(-1 != nIndex)
wchar_t dir[_MAX_DIR]; return sSourcePath.Left(nIndex + 1) + sTargetExt;
wchar_t fname[_MAX_FNAME]; return sSourcePath;
wchar_t ext[_MAX_EXT];
_wsplitpath(sSourcePath, drive, dir, fname, ext);
_tmakepath(path_buffer, drive, dir, fname, sTargetExt);
return CString(path_buffer);
} }
void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter) void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter)
{ {
......
#include "CSVReader.h" #include "CSVReader.h"
#include <map> #include <map>
...@@ -12,7 +12,7 @@ namespace CSVReader ...@@ -12,7 +12,7 @@ namespace CSVReader
sText.Delete(nIndex); sText.Delete(nIndex);
oDeleteChars.pop(); oDeleteChars.pop();
} }
// // Пустую не пишем
if (0 == sText.GetLength()) if (0 == sText.GetLength())
return; return;
...@@ -23,7 +23,7 @@ namespace CSVReader ...@@ -23,7 +23,7 @@ namespace CSVReader
LONG lValue = wcstol(sText, &pEndPtr, 10); LONG lValue = wcstol(sText, &pEndPtr, 10);
if (NULL != *pEndPtr) if (NULL != *pEndPtr)
{ {
// // Не число
pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr); pCell->m_oType->SetValue(SimpleTypes::Spreadsheet::celltypeInlineStr);
pCell->m_oRichText.Init(); pCell->m_oRichText.Init();
OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText(); OOX::Spreadsheet::CText *pText = new OOX::Spreadsheet::CText();
...@@ -32,7 +32,7 @@ namespace CSVReader ...@@ -32,7 +32,7 @@ namespace CSVReader
} }
else else
{ {
// // Число
pCell->m_oValue.Init(); pCell->m_oValue.Init();
pCell->m_oValue->m_sText = sText; pCell->m_oValue->m_sText = sText;
} }
...@@ -48,14 +48,14 @@ namespace CSVReader ...@@ -48,14 +48,14 @@ namespace CSVReader
pCell->m_oRef = OOX::Spreadsheet::CWorksheet::combineRef(nRow, nCol); pCell->m_oRef = OOX::Spreadsheet::CWorksheet::combineRef(nRow, nCol);
oRow.m_arrItems.push_back(pCell); oRow.m_arrItems.push_back(pCell);
} }
void ReadFromCsvToXlsx(CString &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, CONST WCHAR wcDelimiter) void ReadFromCsvToXlsx(CString &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter)
{ {
// Workbook // Создадим Workbook
oXlsx.CreateWorkbook(); oXlsx.CreateWorkbook();
// // Создадим стили
oXlsx.CreateStyles(); oXlsx.CreateStyles();
// wrap- // Добавим стили для wrap-а
OOX::Spreadsheet::CStyles *pStyles = oXlsx.GetStyles(); OOX::Spreadsheet::CStyles *pStyles = oXlsx.GetStyles();
pStyles->m_oCellXfs.Init(); pStyles->m_oCellXfs.Init();
pStyles->m_oCellXfs->m_oCount.Init(); pStyles->m_oCellXfs->m_oCount.Init();
...@@ -114,16 +114,22 @@ namespace CSVReader ...@@ -114,16 +114,22 @@ namespace CSVReader
BYTE* pFileData = new BYTE[oFile.GetFileSize()]; BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize); oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile(); oFile.CloseFile();
//todo
#ifdef _WIN32
INT nSize = MultiByteToWideChar(nCodePage, 0, (LPCSTR)pFileData, nFileSize, NULL, 0); INT nSize = MultiByteToWideChar(nCodePage, 0, (LPCSTR)pFileData, nFileSize, NULL, 0);
WCHAR *pTemp = new WCHAR [nSize]; WCHAR *pTemp = new WCHAR [nSize];
memset(pTemp, 0, sizeof(WCHAR) * nSize); memset(pTemp, 0, sizeof(WCHAR) * nSize);
MultiByteToWideChar (nCodePage, 0, (LPCSTR)pFileData, nFileSize, pTemp, nSize); MultiByteToWideChar (nCodePage, 0, (LPCSTR)pFileData, nFileSize, pTemp, nSize);
#else
std::wstring sFileDataW = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8(pFileData, nFileSize);
INT nSize = sFileDataW.length();
const WCHAR *pTemp = sFileDataW.c_str();
#endif
CONST WCHAR wcNewLineN = _T('\n'); const WCHAR wcNewLineN = _T('\n');
CONST WCHAR wcNewLineR = _T('\r'); const WCHAR wcNewLineR = _T('\r');
CONST WCHAR wcQuote = _T('"'); const WCHAR wcQuote = _T('"');
CONST WCHAR wcTab = _T('\t'); const WCHAR wcTab = _T('\t');
BOOL bIsWrap = FALSE; BOOL bIsWrap = FALSE;
WCHAR wcCurrent; WCHAR wcCurrent;
...@@ -158,7 +164,7 @@ namespace CSVReader ...@@ -158,7 +164,7 @@ namespace CSVReader
{ {
if (bInQuote) if (bInQuote)
{ {
// Wrap // Добавим Wrap
bIsWrap = TRUE; bIsWrap = TRUE;
continue; continue;
} }
...@@ -172,7 +178,7 @@ namespace CSVReader ...@@ -172,7 +178,7 @@ namespace CSVReader
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1]) if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{ {
// \r\n 1 // На комбинацию \r\n должен быть только 1 перенос
++nIndex; ++nIndex;
} }
...@@ -189,16 +195,16 @@ namespace CSVReader ...@@ -189,16 +195,16 @@ namespace CSVReader
// Quote // Quote
if (FALSE == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize) if (FALSE == bInQuote && nStartCell == nIndex && nIndex + 1 != nSize)
{ {
// ( ) // Начало новой ячейки (только если мы сразу после разделителя и не в конце файла)
bInQuote = !bInQuote; bInQuote = !bInQuote;
nStartCell = nIndex + 1; nStartCell = nIndex + 1;
} }
else if (TRUE == bInQuote) else if (TRUE == bInQuote)
{ {
// // Нужно удалить кавычку ограничитель
oDeleteChars.push(nIndex); oDeleteChars.push(nIndex);
// , (1997,Ford,E350,"Super, ""luxurious"" truck") // Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1]) if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex; ++nIndex;
else else
...@@ -223,11 +229,12 @@ namespace CSVReader ...@@ -223,11 +229,12 @@ namespace CSVReader
{ {
RELEASEOBJECT(pRow); RELEASEOBJECT(pRow);
} }
#ifdef _WIN32
RELEASEARRAYOBJECTS(pTemp); RELEASEARRAYOBJECTS(pTemp);
#endif
} }
std::map<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets(); std::map<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
arrWorksheets [sSheetRId] = pWorksheet; arrWorksheets [sSheetRId] = pWorksheet;
} }
} }
\ No newline at end of file
...@@ -967,7 +967,7 @@ namespace BinXlsxRW{ ...@@ -967,7 +967,7 @@ namespace BinXlsxRW{
{ {
CString sContentTypesPath = m_oSaveParams.sThemePath.Right(nIndex); CString sContentTypesPath = m_oSaveParams.sThemePath.Right(nIndex);
sContentTypesPath.Replace('\\', '/'); sContentTypesPath.Replace('\\', '/');
m_oSaveParams.sAdditionalContentTypes.AppendFormat(_T("<Override PartName=\"/%s/%s\" ContentType=\"application/vnd.openxmlformats-officedocument.themeOverride+xml\"/>"), sContentTypesPath, sThemeOverrideName); m_oSaveParams.sAdditionalContentTypes.AppendFormat(_T("<Override PartName=\"/%s/%s\" ContentType=\"application/vnd.openxmlformats-officedocument.themeOverride+xml\"/>"), (const TCHAR *) sContentTypesPath, (const TCHAR *) sThemeOverrideName);
} }
res = c_oSerConstants::ReadUnknown; res = c_oSerConstants::ReadUnknown;
...@@ -10701,4 +10701,4 @@ namespace BinXlsxRW{ ...@@ -10701,4 +10701,4 @@ namespace BinXlsxRW{
m_oBcw.WriteItemEnd(nCurPos); m_oBcw.WriteItemEnd(nCurPos);
} }
} }
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define BINARY_COMMON_READER #define BINARY_COMMON_READER
#include "../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h" #include "../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h"
#include "../../XlsxSerializerCom/Common/BinReaderWriterDefines.h"
namespace BinXlsxRW { namespace BinXlsxRW {
template <typename CallbackType > template <typename CallbackType >
......
#include "CSVWriter.h" #include "CSVWriter.h"
#ifndef CP_UTF8
#define CP_UTF8 65001
#endif
namespace CSVWriter namespace CSVWriter
{ {
...@@ -10,8 +14,8 @@ namespace CSVWriter ...@@ -10,8 +14,8 @@ namespace CSVWriter
if (0 == nCountChars && !bIsEnd) if (0 == nCountChars && !bIsEnd)
return; return;
CONST INT c_nSize = 1048576; // 1024 * 1024 const INT c_nSize = 1048576; // 1024 * 1024
CONST INT nSizeWchar = sizeof(WCHAR); const INT nSizeWchar = sizeof(WCHAR);
if (NULL == *pWriteBuffer) if (NULL == *pWriteBuffer)
{ {
*pWriteBuffer = new WCHAR[c_nSize]; *pWriteBuffer = new WCHAR[c_nSize];
...@@ -21,19 +25,28 @@ namespace CSVWriter ...@@ -21,19 +25,28 @@ namespace CSVWriter
if (nCountChars + nCurrentIndex > c_nSize || bIsEnd) if (nCountChars + nCurrentIndex > c_nSize || bIsEnd)
{ {
// , // Буффер заполнился, пишем
if (nCodePage == CP_UTF16) if (nCodePage == CP_UTF16)
{ {
pFile->WriteFile((BYTE*)*pWriteBuffer, sizeof (WCHAR) * nCurrentIndex); pFile->WriteFile((BYTE*)*pWriteBuffer, sizeof (WCHAR) * nCurrentIndex);
} }
else else
{ {
//todo
#ifdef _WIN32
INT nSize = WideCharToMultiByte(nCodePage, 0, *pWriteBuffer, nCurrentIndex, NULL, NULL, NULL, NULL); INT nSize = WideCharToMultiByte(nCodePage, 0, *pWriteBuffer, nCurrentIndex, NULL, NULL, NULL, NULL);
CHAR *pString = new CHAR [nSize]; CHAR *pString = new CHAR [nSize];
memset(pString, 0, sizeof (CHAR) * nSize); memset(pString, 0, sizeof (CHAR) * nSize);
WideCharToMultiByte (CP_UTF8, 0, *pWriteBuffer, -1, pString, nSize, NULL, NULL); WideCharToMultiByte (nCodePage, 0, *pWriteBuffer, -1, pString, nSize, NULL, NULL);
pFile->WriteFile((BYTE*)pString, sizeof (CHAR) * nSize); pFile->WriteFile((BYTE*)pString, sizeof (CHAR) * nSize);
RELEASEARRAYOBJECTS(pString); RELEASEARRAYOBJECTS(pString);
#else
BYTE* pUtf8 = NULL;
long nUtf8Size;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(*pWriteBuffer, nCurrentIndex, pUtf8, nUtf8Size);
pFile->WriteFile(pUtf8, nUtf8Size);
RELEASEARRAYOBJECTS(pUtf8);
#endif
} }
memset(*pWriteBuffer, 0, nSizeWchar * c_nSize); memset(*pWriteBuffer, 0, nSizeWchar * c_nSize);
...@@ -46,25 +59,25 @@ namespace CSVWriter ...@@ -46,25 +59,25 @@ namespace CSVWriter
nCurrentIndex += nCountChars; nCurrentIndex += nCountChars;
} }
} }
void WriteFromXlsxToCsv(CString &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, CONST WCHAR wcDelimiter) void WriteFromXlsxToCsv(CString &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter)
{ {
NSFile::CFileBinary oFile; NSFile::CFileBinary oFile;
oFile.CreateFileW(string2std_string(sFileDst)); oFile.CreateFileW(string2std_string(sFileDst));
// // Нужно записать шапку
if (CP_UTF8 == nCodePage) if (CP_UTF8 == nCodePage)
{ {
UCHAR arUTF8[3] = {0xEF, 0xBB, 0xBF}; BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
oFile.WriteFile(arUTF8, 3); oFile.WriteFile(arUTF8, 3);
} }
else if (CP_UTF16 == nCodePage) else if (CP_UTF16 == nCodePage)
{ {
UCHAR arUTF16[2] = {0xFF, 0xFE}; BYTE arUTF16[2] = {0xFF, 0xFE};
oFile.WriteFile(arUTF16, 2); oFile.WriteFile(arUTF16, 2);
} }
else if (CP_unicodeFFFE == nCodePage) else if (CP_unicodeFFFE == nCodePage)
{ {
UCHAR arBigEndian[2] = {0xFE, 0xFF}; BYTE arBigEndian[2] = {0xFE, 0xFF};
oFile.WriteFile(arBigEndian, 2); oFile.WriteFile(arBigEndian, 2);
} }
...@@ -73,7 +86,7 @@ namespace CSVWriter ...@@ -73,7 +86,7 @@ namespace CSVWriter
INT nCurrentIndex = 0; INT nCurrentIndex = 0;
WCHAR *pWriteBuffer = NULL; WCHAR *pWriteBuffer = NULL;
CString sSheetRId = _T("Sheet1"); // rId, CString sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook(); OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook();
if (NULL != pWorkbook) if (NULL != pWorkbook)
{ {
...@@ -106,7 +119,7 @@ namespace CSVWriter ...@@ -106,7 +119,7 @@ namespace CSVWriter
{ {
OOX::Spreadsheet::CSharedStrings *pSharedStrings = oXlsx.GetSharedStrings(); OOX::Spreadsheet::CSharedStrings *pSharedStrings = oXlsx.GetSharedStrings();
CString sDelimiter = _T(""); sDelimiter += wcDelimiter; CString sDelimiter = _T(""); sDelimiter += wcDelimiter;
CONST WCHAR wcQuote = _T('"'); const WCHAR wcQuote = _T('"');
CString sEscape = _T("\"\n"); CString sEscape = _T("\"\n");
sEscape += wcDelimiter; sEscape += wcDelimiter;
...@@ -182,10 +195,10 @@ namespace CSVWriter ...@@ -182,10 +195,10 @@ namespace CSVWriter
} }
} }
// MS Excel ( ) // Теперь мы пишем как MS Excel (новую строку записываем в файл)
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage); WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, TRUE); WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, TRUE);
RELEASEARRAYOBJECTS(pWriteBuffer); RELEASEARRAYOBJECTS(pWriteBuffer);
oFile.CloseFile(); oFile.CloseFile();
} }
} }
\ No newline at end of file
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