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 @@
#include "../../ASCOfficePPTXFile/Editor/FontPicker.h"
#include "../../ASCOfficeUtils/ASCOfficeUtilsLib/OfficeUtils.h"
#ifndef _WIN32
#include "../../DesktopEditor/common/Types.h"
#endif
int BinDocxRW::g_nCurFormatVersion = 0;
BinDocxRW::CDocxSerializer::CDocxSerializer()
......@@ -65,8 +61,6 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C
oDrawingConverter.SetFontManager(pFontManager);
NSBinPptxRW::CBinaryFileWriter& oBufferedStream = *oDrawingConverter.m_pBinaryWriter;
#ifdef _WIN32
NSFontCutter::CEmbeddedFontsManager* pEmbeddedFontsManager = NULL;
if(false == m_sEmbeddedFontsDir.IsEmpty())
{
......@@ -92,7 +86,6 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C
ParamsWriter oParamsWriter(oBufferedStream, fp, &oDrawingConverter, pEmbeddedFontsManager);
m_oBinaryFileWriter = new BinaryFileWriter(oParamsWriter);
m_oBinaryFileWriter->intoBindoc(sDstPath);
#endif
BYTE* pbBinBuffer = oBufferedStream.GetBuffer();
int nBinBufferLen = oBufferedStream.GetPosition();
......@@ -115,6 +108,7 @@ bool BinDocxRW::CDocxSerializer::saveToFile(const CString& sSrcFileName, const C
oFile.WriteFile(pbBase64Buffer, nBase64BufferLen);
oFile.CloseFile();
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
}
RELEASEOBJECT(m_oBinaryFileWriter);
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
//strDst64.SetString(pbBase64Buffer, nBase64BufferLen);
strDst64 = pbBase64Buffer;
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
RELEASEARRAYOBJECTS(pBuffer);
oFile.CloseFile();
......
......@@ -282,7 +282,7 @@ namespace XmlUtils
reader = NULL;
m_pStream = NULL;
}
~CXmlLiteReader()
virtual ~CXmlLiteReader()
{
if (NULL != m_pStream)
delete []m_pStream;
......
......@@ -4,13 +4,20 @@
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
#include "../../Common/Base64.h"
#include "../../DesktopEditor/common/Types.h"
#ifndef DISABLE_FILE_DOWNLOADER
#include "../../ASCOfficeDocxFile2/BinReader/FileDownloader.h"
#endif
#include "../../DesktopEditor/common/file.h"
#ifndef CP_UTF8
#define CP_UTF8 65001
#endif
namespace SerializeCommon
{
CString DownloadImage(const CString& strFile)
{
#ifndef DISABLE_FILE_DOWNLOADER
CFileDownloader oDownloader(strFile, FALSE);
oDownloader.Start( 1 );
while ( oDownloader.IsRunned() )
......@@ -23,16 +30,17 @@ namespace SerializeCommon
strFileName = oDownloader.GetFilePath();
}
return strFileName;
#else
return L"";
#endif
}
VOID convertBase64ToImage (NSFile::CFileBinary& oFile, CString &pBase64)
{
INT nUTF8Len = WideCharToMultiByte (CP_UTF8, 0, pBase64, pBase64.GetLength (), NULL, NULL, NULL, NULL);
CHAR *pUTF8String = new CHAR [nUTF8Len + 1];
memset(pUTF8String, 0, sizeof (CHAR) * (nUTF8Len + 1));
WideCharToMultiByte (CP_UTF8, 0, pBase64, -1, pUTF8String, nUTF8Len, NULL, NULL);
CStringA sUnicode; sUnicode = pUTF8String;
delete[] pUTF8String;
BYTE* pUtf8 = NULL;
long nUtf8Size;
NSFile::CUtf8Converter::GetUtf8StringFromUnicode(pBase64.GetString(), pBase64.GetLength(), pUtf8, nUtf8Size);
CStringA sUnicode((char*)pUtf8, nUtf8Size);
RELEASEARRAYOBJECTS(pUtf8);
// "data:image/jpg;base64,"
int nShift = 0;
......@@ -60,14 +68,10 @@ namespace SerializeCommon
}
CString changeExtention(const CString& sSourcePath, const CString& sTargetExt)
{
wchar_t path_buffer[_MAX_PATH];
wchar_t drive[_MAX_DRIVE];
wchar_t dir[_MAX_DIR];
wchar_t fname[_MAX_FNAME];
wchar_t ext[_MAX_EXT];
_wsplitpath(sSourcePath, drive, dir, fname, ext);
_tmakepath(path_buffer, drive, dir, fname, sTargetExt);
return CString(path_buffer);
int nIndex = sSourcePath.ReverseFind('.');
if(-1 != nIndex)
return sSourcePath.Left(nIndex + 1) + sTargetExt;
return sSourcePath;
}
void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter)
{
......
#include "CSVReader.h"
#include "CSVReader.h"
#include <map>
......@@ -12,7 +12,7 @@ namespace CSVReader
sText.Delete(nIndex);
oDeleteChars.pop();
}
//
// Пустую не пишем
if (0 == sText.GetLength())
return;
......@@ -23,7 +23,7 @@ namespace CSVReader
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();
......@@ -32,7 +32,7 @@ namespace CSVReader
}
else
{
//
// Число
pCell->m_oValue.Init();
pCell->m_oValue->m_sText = sText;
}
......@@ -48,14 +48,14 @@ namespace CSVReader
pCell->m_oRef = OOX::Spreadsheet::CWorksheet::combineRef(nRow, nCol);
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.CreateStyles();
// wrap-
// Добавим стили для wrap-а
OOX::Spreadsheet::CStyles *pStyles = oXlsx.GetStyles();
pStyles->m_oCellXfs.Init();
pStyles->m_oCellXfs->m_oCount.Init();
......@@ -114,16 +114,22 @@ namespace CSVReader
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile();
//todo
#ifdef _WIN32
INT nSize = MultiByteToWideChar(nCodePage, 0, (LPCSTR)pFileData, nFileSize, NULL, 0);
WCHAR *pTemp = new WCHAR [nSize];
memset(pTemp, 0, sizeof(WCHAR) * 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 wcNewLineR = _T('\r');
CONST WCHAR wcQuote = _T('"');
CONST WCHAR wcTab = _T('\t');
const WCHAR wcNewLineN = _T('\n');
const WCHAR wcNewLineR = _T('\r');
const WCHAR wcQuote = _T('"');
const WCHAR wcTab = _T('\t');
BOOL bIsWrap = FALSE;
WCHAR wcCurrent;
......@@ -158,7 +164,7 @@ namespace CSVReader
{
if (bInQuote)
{
// Wrap
// Добавим Wrap
bIsWrap = TRUE;
continue;
}
......@@ -172,7 +178,7 @@ namespace CSVReader
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{
// \r\n 1
// На комбинацию \r\n должен быть только 1 перенос
++nIndex;
}
......@@ -189,16 +195,16 @@ namespace CSVReader
// 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")
// Если следующий символ кавычка, то мы не закончили ограничитель строки (1997,Ford,E350,"Super, ""luxurious"" truck")
if (nIndex + 1 != nSize && wcQuote == pTemp[nIndex + 1])
++nIndex;
else
......@@ -223,11 +229,12 @@ namespace CSVReader
{
RELEASEOBJECT(pRow);
}
#ifdef _WIN32
RELEASEARRAYOBJECTS(pTemp);
#endif
}
std::map<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
arrWorksheets [sSheetRId] = pWorksheet;
}
}
\ No newline at end of file
}
......@@ -967,7 +967,7 @@ namespace BinXlsxRW{
{
CString sContentTypesPath = m_oSaveParams.sThemePath.Right(nIndex);
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;
......@@ -10701,4 +10701,4 @@ namespace BinXlsxRW{
m_oBcw.WriteItemEnd(nCurPos);
}
}
}
\ No newline at end of file
}
......@@ -2,6 +2,7 @@
#define BINARY_COMMON_READER
#include "../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h"
#include "../../XlsxSerializerCom/Common/BinReaderWriterDefines.h"
namespace BinXlsxRW {
template <typename CallbackType >
......
#include "CSVWriter.h"
#include "CSVWriter.h"
#ifndef CP_UTF8
#define CP_UTF8 65001
#endif
namespace CSVWriter
{
......@@ -10,8 +14,8 @@ namespace CSVWriter
if (0 == nCountChars && !bIsEnd)
return;
CONST INT c_nSize = 1048576; // 1024 * 1024
CONST INT nSizeWchar = sizeof(WCHAR);
const INT c_nSize = 1048576; // 1024 * 1024
const INT nSizeWchar = sizeof(WCHAR);
if (NULL == *pWriteBuffer)
{
*pWriteBuffer = new WCHAR[c_nSize];
......@@ -21,19 +25,28 @@ namespace CSVWriter
if (nCountChars + nCurrentIndex > c_nSize || bIsEnd)
{
// ,
// Буффер заполнился, пишем
if (nCodePage == CP_UTF16)
{
pFile->WriteFile((BYTE*)*pWriteBuffer, sizeof (WCHAR) * nCurrentIndex);
}
else
{
//todo
#ifdef _WIN32
INT nSize = WideCharToMultiByte(nCodePage, 0, *pWriteBuffer, nCurrentIndex, NULL, NULL, NULL, NULL);
CHAR *pString = new 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);
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);
......@@ -46,25 +59,25 @@ namespace CSVWriter
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;
oFile.CreateFileW(string2std_string(sFileDst));
//
// Нужно записать шапку
if (CP_UTF8 == nCodePage)
{
UCHAR arUTF8[3] = {0xEF, 0xBB, 0xBF};
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
oFile.WriteFile(arUTF8, 3);
}
else if (CP_UTF16 == nCodePage)
{
UCHAR arUTF16[2] = {0xFF, 0xFE};
BYTE arUTF16[2] = {0xFF, 0xFE};
oFile.WriteFile(arUTF16, 2);
}
else if (CP_unicodeFFFE == nCodePage)
{
UCHAR arBigEndian[2] = {0xFE, 0xFF};
BYTE arBigEndian[2] = {0xFE, 0xFF};
oFile.WriteFile(arBigEndian, 2);
}
......@@ -73,7 +86,7 @@ namespace CSVWriter
INT nCurrentIndex = 0;
WCHAR *pWriteBuffer = NULL;
CString sSheetRId = _T("Sheet1"); // rId,
CString sSheetRId = _T("Sheet1"); // Читаем не по rId, а по имени листа
OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook();
if (NULL != pWorkbook)
{
......@@ -106,7 +119,7 @@ namespace CSVWriter
{
OOX::Spreadsheet::CSharedStrings *pSharedStrings = oXlsx.GetSharedStrings();
CString sDelimiter = _T(""); sDelimiter += wcDelimiter;
CONST WCHAR wcQuote = _T('"');
const WCHAR wcQuote = _T('"');
CString sEscape = _T("\"\n");
sEscape += wcDelimiter;
......@@ -182,10 +195,10 @@ namespace CSVWriter
}
}
// MS Excel ( )
// Теперь мы пишем как MS Excel (новую строку записываем в файл)
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, TRUE);
RELEASEARRAYOBJECTS(pWriteBuffer);
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