Commit 4a678df5 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

git-svn-id:...

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@61926 954022d7-b5bf-4e40-9824-e11837661b57
parent 82f3f4c4
#pragma once
#include "resource.h"
#include "Reader/BinaryWriter.h"
#include "Writer/BinaryReader.h"
#include "../ASCOfficeDocxFile2/DocWrapper/XlsxSerializer.h"
#include "../ASCOfficePPTXFile/Editor/FontPicker.h"
#include "../ASCOfficeDocxFile2/DocWrapper/FontProcessor.h"
#include "../Common/OfficeFileTemplate.h"
int g_nCurFormatVersion = 0;
[
object,
uuid("87476A4D-6A42-44e9-A947-42B8E8613070"),
dual, helpstring("IAVSOfficeXlsxSerizer Interface"),
pointer_default(unique)
]
__interface IAVSOfficeXlsxSerizer : public IAVSOfficeFileTemplate
{
[id(20)] HRESULT SetFontDir([in] BSTR bsFontDir);
[id(30)] HRESULT LoadChart([in] BSTR bsFilename, [out, satype("BYTE")] SAFEARRAY** ppBinary);
[id(31)] HRESULT SaveChart([in, satype("BYTE")] SAFEARRAY* pBinaryObj, [in] LONG lStart, [in] LONG lLength, [in] BSTR bsFilename, [in] BSTR bsContentTypePath, [out] BSTR* bsContentTypeElement);
[id(32)] HRESULT SetDrawingConverter([in] IUnknown* pDocument);
[id(120)] HRESULT SetAdditionalParam([in] BSTR ParamName, [in] VARIANT ParamValue);
[id(130)] HRESULT GetAdditionalParam([in] BSTR ParamName, [out, retval] VARIANT* ParamValue);
};
[
coclass,
default(IAVSOfficeXlsxSerizer),
event_receiver(native),
threading(apartment),
vi_progid("ASCOfficeXlsxSerizer.AVSDocume"),
progid("ASCOfficeXlsxSerizer.AVSDocu.1"),
version(1.0),
uuid("2A6514F2-0C01-4759-89CB-68C38669337D"),
helpstring("ASCOfficeXlsxSerizer Class")
]
class ATL_NO_VTABLE CAVSOfficeXlsxSerizer : public IAVSOfficeXlsxSerizer
{
private:
BinXlsxRW::CXlsxSerializer m_oXlsxSerializer;
public:
CAVSOfficeXlsxSerizer()
{
}
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
STDMETHOD(LoadFromFile)(BSTR sSrcFileName, BSTR bstrDstPath, BSTR bstrXMLOptions)
{
CString sDstPath = bstrDstPath;
CString sMediaPath;
m_oXlsxSerializer.CreateXlsxFolders(CString(bstrXMLOptions), sDstPath, sMediaPath);
bool bRes = m_oXlsxSerializer.loadFromFile(CString(sSrcFileName), sDstPath, CString(bstrXMLOptions), sMediaPath);
return bRes ? S_OK : S_FALSE;
return S_OK;
}
STDMETHOD(SaveToFile)(BSTR sDstFileName, BSTR sSrcPath, BSTR sXMLOptions)
{
bool bRes = m_oXlsxSerializer.saveToFile(CString(sDstFileName), CString(sSrcPath), CString(sXMLOptions)) ? S_OK : S_FALSE;
return bRes ? S_OK : S_FALSE;
}
STDMETHOD(LoadChart)(BSTR bsFilename, SAFEARRAY** ppBinary)
{
unsigned char* pData = NULL;
long lDataSize = 0;
bool bRes = true;
//m_oXlsxSerializer.loadChart(CString(bsFilename), &pData, lDataSize);
if(NULL != pData && lDataSize > 0)
{
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lDataSize;
LPSAFEARRAY pArray = SafeArrayCreate(VT_UI1, 1, rgsabound);
BYTE* pDataD = (BYTE*)pArray->pvData;
BYTE* pDataS = pData;
memcpy(pDataD, pDataS, lDataSize);
*ppBinary = pArray;
}
RELEASEARRAYOBJECTS(pData);
return bRes ? S_OK : S_FALSE; }
STDMETHOD(SaveChart)(SAFEARRAY* pBinaryObj, LONG lStart, LONG lLength, BSTR bsFilename, BSTR bsContentTypePath, BSTR* bsContentTypeElement)
{
CString* sContentTypeElement = NULL;
bool bRes = true;
//m_oXlsxSerializer.saveChart(pBinaryObj, lStart, lLength, CString(bsFilename), CString(bsContentTypePath), &sContentTypeElement);
if(NULL != sContentTypeElement)
*bsContentTypeElement = sContentTypeElement->AllocSysString();
return bRes ? S_OK : S_FALSE;
}
STDMETHOD(SetDrawingConverter)(IUnknown* pDocument)
{
return S_OK;
}
STDMETHOD(SetFontDir)(BSTR bsFontDir)
{
m_oXlsxSerializer.setFontDir(CString(bsFontDir));
return S_OK;
}
STDMETHOD(SetAdditionalParam)(BSTR ParamName, VARIANT ParamValue)
{
CString sParamName; sParamName = ParamName;
if (_T("EmbeddedFontsDirectory") == sParamName && ParamValue.vt == VT_BSTR)
{
m_oXlsxSerializer.setEmbeddedFontsDir(CString(ParamValue.bstrVal));
return S_OK;
}
return S_OK;
}
STDMETHOD(GetAdditionalParam)(BSTR ParamName, VARIANT* ParamValue)
{
return S_OK;
}
private:
DocWrapper::FontProcessor m_oFontProcessor;
};
\ No newline at end of file
This diff is collapsed.
#include "Common.h"
#include "BinReaderWriterDefines.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
#include "../../Common/Base64.h"
#include "../../DesktopEditor/common/Types.h"
#ifndef DISABLE_FILE_DOWNLOADER
#include "../../Common/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() )
{
::Sleep( 10 );
}
CString strFileName;
if ( oDownloader.IsFileDownloaded() )
{
strFileName = oDownloader.GetFilePath();
}
return strFileName;
#else
return L"";
#endif
}
VOID convertBase64ToImage (NSFile::CFileBinary& oFile, CString &pBase64)
{
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;
int nIndex = sUnicode.Find("base64,");
if(-1 != nIndex)
{
nShift = nIndex + 7;
}
//
LONG lFileSize = sUnicode.GetLength () - nShift;
INT nDstLength = lFileSize;
BYTE *pBuffer = new BYTE [lFileSize];
memset(pBuffer, 0, lFileSize);
Base64::Base64Decode ((LPCSTR)sUnicode.GetBuffer () + nShift, lFileSize, pBuffer, &nDstLength);
//
oFile.WriteFile(pBuffer, nDstLength);
RELEASEARRAYOBJECTS (pBuffer);
}
long Round(double val)
{
return (long)(val+ 0.5);
}
CString changeExtention(const CString& sSourcePath, const CString& sTargetExt)
{
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, BYTE& cSaveFileType)
{
result = BinXlsxRW::c_oFileTypes::XLSX;
nCodePage = CP_UTF8;
wcDelimiter = _T(',');
cSaveFileType = BinXlsxRW::c_oFileTypes::XLSX;
nullable<SimpleTypes::CUnsignedDecimalNumber<>> fileType;
nullable<SimpleTypes::CUnsignedDecimalNumber<>> codePage;
nullable<SimpleTypes::CUnsignedDecimalNumber<>> saveFileType;
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_Read_else_if (oReader, _T("saveFileType"), saveFileType)
WritingElement_ReadAttributes_End(oReader)
if (fileType.IsInit())
result = (BYTE)fileType->GetValue();
if (codePage.IsInit())
nCodePage = (UINT)codePage->GetValue();
if (saveFileType.IsInit())
cSaveFileType = (BYTE)saveFileType->GetValue();
if (delimiter.IsInit())
{
const CString& sDelimiter = delimiter.get();
if (0 < sDelimiter.GetLength())
wcDelimiter = sDelimiter.GetAt(0);
}
break;
}
}
return;
}
}
#ifndef SERIALIZER_COMMON
#define SERIALIZER_COMMON
#if defined(_WIN32) || defined (_WIN64)
#include <atlbase.h>
#include <atlstr.h>
#else
#include "../../Common/DocxFormat/Source/Base/ASCString.h"
#endif
#include "../../DesktopEditor/common/File.h"
#include <string>
#include <vector>
#define BUFFER_GROW_SIZE 1 * 1024 * 1024 //1mb
namespace SerializeCommon
{
CString DownloadImage(const CString& strFile);
VOID convertBase64ToImage (NSFile::CFileBinary& oFile, CString &pBase64);
long Round(double val);
CString changeExtention(const CString& sSourcePath, const CString& sTargetExt);
class CommentData
{
public :
CString sText;
CString sTime;
CString sUserId;
CString sUserName;
CString sQuoteText;
bool Solved;
bool Document;
bool bSolved;
bool bDocument;
std::vector<CommentData*> aReplies;
CommentData()
{
bSolved = false;
bDocument = false;
}
~CommentData()
{
for(int i = 0, length = aReplies.size(); i < length; ++i)
delete aReplies[i];
aReplies.clear();
}
};
void ReadFileType(CString& sXMLOptions, BYTE& result, UINT& nCodePage, WCHAR& wcDelimiter, BYTE& saveFileType);
}
#endif //SERIALIZER_COMMON
This source diff could not be displayed because it is too large. You can view the blob instead.
#include "CSVReader.h"
#include <map>
#include "../../DesktopEditor/common/File.h"
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();
}
// Пустую не пишем
if (0 == sText.GetLength())
return;
OOX::Spreadsheet::CCell *pCell = new OOX::Spreadsheet::CCell();
pCell->m_oType.Init();
WCHAR *pEndPtr;
double dValue = wcstod(sText, &pEndPtr);
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.push_back(pText);
}
else
{
// Число
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.push_back(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.push_back(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.push_back(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_oName.Init();
pSheet->m_oName->Append(_T("Sheet1"));
pSheet->m_oSheetId.Init();
pSheet->m_oSheetId->SetValue(1);
pSheet->m_oRid.Init();
pSheet->m_oRid->SetValue(sSheetRId);
OOX::Spreadsheet::CWorkbook *pWorkbook = oXlsx.GetWorkbook();
pWorkbook->m_oSheets.Init();
pWorkbook->m_oSheets->m_arrItems.push_back(pSheet);
NSFile::CFileBinary oFile;
if(oFile.OpenFile(string2std_string(sFileName)))
{
DWORD nFileSize = 0;
BYTE* pFileData = new BYTE[oFile.GetFileSize()];
oFile.ReadFile(pFileData, oFile.GetFileSize(), nFileSize);
oFile.CloseFile();
//todo
#if defined(_WIN32) || defined (_WIN64)
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');
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.push_back(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;
}
if (wcNewLineR == wcCurrent && nIndex + 1 != nSize && wcNewLineN == pTemp[nIndex + 1])
{
// На комбинацию \r\n должен быть только 1 перенос
++nIndex;
}
nStartCell = nIndex + 1;
pWorksheet->m_oSheetData->m_arrItems.push_back(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.push_back(pRow);
}
else
{
RELEASEOBJECT(pRow);
}
#if defined(_WIN32) || defined (_WIN64)
RELEASEARRAYOBJECTS(pTemp);
#endif
}
std::map<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
arrWorksheets [sSheetRId] = pWorksheet;
}
}
#ifndef CSV_READER
#define CSV_READER
#include <stack>
#if defined(_WIN32) || defined (_WIN64)
#include <atlbase.h>
#include <atlstr.h>
#else
#include "../../Common/DocxFormat/Source/Base/ASCString.h"
#endif
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
#include "../../DesktopEditor/common/File.h"
namespace CSVReader
{
void AddCell(CString &sText, INT nStartCell, std::stack<INT> &oDeleteChars, OOX::Spreadsheet::CRow &oRow, INT nRow, INT nCol, BOOL bIsWrap);
void ReadFromCsvToXlsx(CString &sFileName, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter);
}
#endif //CSV_READER
This diff is collapsed.
This diff is collapsed.
//#include "stdafx.h"
#include "CommonWriter.h"
#include "../Common/BinReaderWriterDefines.h"
namespace BinXlsxRW {
BinaryCommonWriter::BinaryCommonWriter(NSBinPptxRW::CBinaryFileWriter &oCBufferedStream):m_oStream(oCBufferedStream)
{
}
int BinaryCommonWriter::WriteItemStart(BYTE type)
{
//type
m_oStream.WriteBYTE(type);
return WriteItemWithLengthStart();
}
void BinaryCommonWriter::WriteItemEnd(int nStart)
{
WriteItemWithLengthEnd(nStart);
}
int BinaryCommonWriter::WriteItemWithLengthStart()
{
//
int nStartPos = m_oStream.GetPosition();
m_oStream.Skip(4);
return nStartPos;
}
void BinaryCommonWriter::WriteItemWithLengthEnd(int nStart)
{
//Length
int nEnd = m_oStream.GetPosition();
m_oStream.SetPosition(nStart);
m_oStream.WriteLONG(nEnd - nStart - 4);
m_oStream.SetPosition(nEnd);
}
void BinaryCommonWriter::WriteColor(const OOX::Spreadsheet::CColor& color, OOX::Spreadsheet::CIndexedColors* pIndexedColors, OOX::CTheme* theme)
{
if(color.m_oAuto.IsInit() && color.m_oAuto->ToBool())
{
m_oStream.WriteBYTE(c_oSer_ColorObjectType::Type);
m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
m_oStream.WriteBYTE(c_oSer_ColorType::Auto);
}
else
{
bool bEmpty = true;
SimpleTypes::Spreadsheet::CHexColor oRgbColor;
if(color.m_oIndexed.IsInit())
{
int nIndex = (int)color.m_oIndexed->GetValue();
if(NULL != pIndexedColors && nIndex < pIndexedColors->m_arrItems.size())
{
OOX::Spreadsheet::CRgbColor* pRgbColor = pIndexedColors->m_arrItems[nIndex];
if(pRgbColor->m_oRgb.IsInit())
{
bEmpty = false;
oRgbColor = pRgbColor->m_oRgb.get();
}
}
else
{
unsigned char ucA;
unsigned char ucR;
unsigned char ucG;
unsigned char ucB;
if(OOX::Spreadsheet::CIndexedColors::GetDefaultRGBAByIndex(nIndex, ucR, ucG, ucB, ucA))
{
bEmpty = false;
oRgbColor.Set_A(ucA);
oRgbColor.Set_R(ucR);
oRgbColor.Set_G(ucG);
oRgbColor.Set_B(ucB);
}
}
}
else if(color.m_oRgb.IsInit())
{
bEmpty = false;
oRgbColor = color.m_oRgb.get();
}
if(color.m_oThemeColor.IsInit())
{
m_oStream.WriteBYTE(c_oSer_ColorObjectType::Theme);
m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
m_oStream.WriteBYTE((BYTE)color.m_oThemeColor->GetValue());
}
if(color.m_oTint.IsInit())
{
m_oStream.WriteBYTE(c_oSer_ColorObjectType::Tint);
m_oStream.WriteBYTE(c_oSerPropLenType::Double);
m_oStream.WriteDoubleReal(color.m_oTint->GetValue());
}
if(!bEmpty)
{
m_oStream.WriteBYTE(c_oSer_ColorObjectType::Rgb);
m_oStream.WriteBYTE(c_oSerPropLenType::Long);
m_oStream.WriteLONG(oRgbColor.ToInt());
}
}
}
void BinaryCommonWriter::WriteBytesArray(BYTE* pData, long nDataSize)
{
int nCurPos = WriteItemWithLengthStart();
m_oStream.WriteBYTEArray(pData, nDataSize);
WriteItemWithLengthEnd(nCurPos);
}
}
\ No newline at end of file
#ifndef COMMON_WRITER
#define COMMON_WRITER
#include "../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
namespace BinXlsxRW {
class BinaryCommonWriter
{
public:
NSBinPptxRW::CBinaryFileWriter &m_oStream;
BinaryCommonWriter(NSBinPptxRW::CBinaryFileWriter &oCBufferedStream);
int WriteItemStart(BYTE type);
void WriteItemEnd(int nStart);
int WriteItemWithLengthStart();
void WriteItemWithLengthEnd(int nStart);
void WriteColor(const OOX::Spreadsheet::CColor& color, OOX::Spreadsheet::CIndexedColors* pIndexedColors, OOX::CTheme* theme);
void WriteBytesArray(BYTE* pData, long nDataSize);
};
}
#endif // #ifndef COMMON_WRITER
\ No newline at end of file
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by XlsxSerializerCom.rc
//
#define IDS_PROJNAME 100
#define IDR_XLSXSERIALIZERCOM 101
#define IDB_DEFAULT_XLSX_THEME 201
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 102
#endif
#endif
#ifndef BINARY_COMMON_READER
#define BINARY_COMMON_READER
#include "../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h"
#include "../../XlsxSerializerCom/Common/BinReaderWriterDefines.h"
namespace BinXlsxRW {
template <typename CallbackType >
class Binary_CommonReader
{
protected:
NSBinPptxRW::CBinaryFileReader& m_oBufferedStream;
typedef int (CallbackType::*funcArg)(BYTE type, long length, void* arg);
public:
Binary_CommonReader(NSBinPptxRW::CBinaryFileReader& poBufferedStream):m_oBufferedStream(poBufferedStream)
{
}
int ReadTable(funcArg fReadFunction, void* poFuncObj, void* arg = NULL)
{
int res = c_oSerConstants::ReadOk;
//stLen
res = m_oBufferedStream.Peek(4) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;
if(c_oSerConstants::ReadOk != res)
return res;
long stLen = m_oBufferedStream.GetLong();
// get
res = m_oBufferedStream.Peek(stLen) == false ? c_oSerConstants::ErrorStream : c_oSerConstants::ReadOk;
if(c_oSerConstants::ReadOk != res)
return res;
return Read1(stLen, fReadFunction, poFuncObj, arg);
}
int Read1(long stLen, funcArg fReadFunction, void* poFuncObj, void* arg = NULL)
{
int res = c_oSerConstants::ReadOk;
long stCurPos = 0;
long start_pos = m_oBufferedStream.GetPos();
while(stCurPos < stLen)
{
//stItem
BYTE type = m_oBufferedStream.GetUChar();
ULONG length = m_oBufferedStream.GetULong();
if (length + stCurPos > stLen)
{
// -
m_oBufferedStream.Seek(start_pos + stLen);
return c_oSerConstants::ReadOk;
}
res = (((CallbackType*)poFuncObj)->*fReadFunction)(type, length, arg);
if(res == c_oSerConstants::ReadUnknown && length > 0)
{
m_oBufferedStream.GetPointer(length);
res = c_oSerConstants::ReadOk;
}
else if(res != c_oSerConstants::ReadOk)
return res;
stCurPos += length + 5;
}
return res;
}
int Read2(long stLen, funcArg fReadFunction, void* poFuncObj, void* arg = NULL)
{
int res = c_oSerConstants::ReadOk;
long stCurPos = 0;
while(stCurPos < stLen)
{
//stItem
BYTE type = m_oBufferedStream.GetUChar();
long lenType = m_oBufferedStream.GetUChar();
int nCurPosShift = 2;
int nRealLen;
switch(lenType)
{
case c_oSerPropLenType::Null: nRealLen = 0;break;
case c_oSerPropLenType::Byte: nRealLen = 1;break;
case c_oSerPropLenType::Short: nRealLen = 2;break;
case c_oSerPropLenType::Three: nRealLen = 3;break;
case c_oSerPropLenType::Long: nRealLen = 4;break;
case c_oSerPropLenType::Double: nRealLen = 8;break;
case c_oSerPropLenType::Variable:
nRealLen = m_oBufferedStream.GetLong();
nCurPosShift += 4;
break;
default:return c_oSerConstants::ErrorUnknown;
}
res = (((CallbackType*)poFuncObj)->*fReadFunction)(type, nRealLen, arg);
if(res == c_oSerConstants::ReadUnknown)
{
m_oBufferedStream.GetPointer(nRealLen);
res = c_oSerConstants::ReadOk;
}
else if(res != c_oSerConstants::ReadOk)
return res;
stCurPos += nRealLen + nCurPosShift;
}
return res;
}
};
}
#endif // #ifndef BINARY_COMMON_READER
This diff is collapsed.
#include "CSVWriter.h"
#ifndef CP_UTF8
#define CP_UTF8 65001
#endif
namespace CSVWriter
{
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, CString &sWriteString, UINT &nCodePage, BOOL bIsEnd)
{
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];
memset(*pWriteBuffer, 0, nSizeWchar * c_nSize);
nCurrentIndex = 0;
}
if (nCountChars + nCurrentIndex > c_nSize || bIsEnd)
{
// Буффер заполнился, пишем
if (nCodePage == CP_UTF16)
{
pFile->WriteFile((BYTE*)*pWriteBuffer, sizeof (WCHAR) * nCurrentIndex);
}
else
{
//todo
#if defined(_WIN32) || defined (_WIN64)
INT nSize = WideCharToMultiByte(nCodePage, 0, *pWriteBuffer, nCurrentIndex, NULL, NULL, NULL, NULL);
CHAR *pString = new CHAR [nSize];
memset(pString, 0, sizeof (CHAR) * nSize);
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);
nCurrentIndex = 0;
}
if (!bIsEnd)
{
memcpy(*pWriteBuffer + nCurrentIndex, sWriteString.GetBuffer(), nCountChars * nSizeWchar);
nCurrentIndex += nCountChars;
}
}
void WriteFromXlsxToCsv(CString &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter, BOOL bJSON)
{
NSFile::CFileBinary oFile;
oFile.CreateFileW(string2std_string(sFileDst));
// Нужно записать шапку
if (CP_UTF8 == nCodePage)
{
BYTE arUTF8[3] = {0xEF, 0xBB, 0xBF};
oFile.WriteFile(arUTF8, 3);
}
else if (CP_UTF16 == nCodePage)
{
BYTE arUTF16[2] = {0xFF, 0xFE};
oFile.WriteFile(arUTF16, 2);
}
else if (CP_unicodeFFFE == nCodePage)
{
BYTE arBigEndian[2] = {0xFE, 0xFF};
oFile.WriteFile(arBigEndian, 2);
}
CString sNewLineN = _T("\n");
LONG lActiveSheet = 0;
INT nCurrentIndex = 0;
WCHAR *pWriteBuffer = NULL;
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.size())
{
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 (для конвертации в CSV нужно использовать name, т.к. это наш бинарник из js-скриптов и еще нет rId
// А для json-а нужно пользовать rId, т.к. при открытии они используются
if (pWorkbook->m_oSheets.IsInit() && 0 <= pWorkbook->m_oSheets->m_arrItems.size())
{
OOX::Spreadsheet::CSheet *pSheet;
if (lActiveSheet <= pWorkbook->m_oSheets->m_arrItems.size())
pSheet = pWorkbook->m_oSheets->m_arrItems[lActiveSheet];
else
pSheet = pWorkbook->m_oSheets->m_arrItems[0];
sSheetRId = bJSON ? pSheet->m_oRid->GetValue() : pSheet->m_oName.get2();
}
std::map<CString, OOX::Spreadsheet::CWorksheet*> &arrWorksheets = oXlsx.GetWorksheets();
std::map<CString, OOX::Spreadsheet::CWorksheet*>::const_iterator pPair = arrWorksheets.find(sSheetRId);
if (pPair != arrWorksheets.end())
{
OOX::Spreadsheet::CWorksheet *pWorksheet = pPair->second;
if (NULL != pWorksheet && pWorksheet->m_oSheetData.IsInit())
{
OOX::Spreadsheet::CSharedStrings *pSharedStrings = oXlsx.GetSharedStrings();
CString sDelimiter = _T(""); sDelimiter += wcDelimiter;
CString sEscape = _T("\"\n");
sEscape += wcDelimiter;
CString sEndJson = CString(_T("]"));
CString sQuote = _T("\"");
CString sDoubleQuote = _T("\"\"");
CString sBkt = CString(_T("["));
CString sBktComma = _T(",[");
if (bJSON)
CSVWriter::WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sBkt, nCodePage);
INT nRowCurrent = 1;
for (INT i = 0; i < pWorksheet->m_oSheetData->m_arrItems.size(); ++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;
if (bJSON)
CSVWriter::WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, (0 == i ? sBkt: sBktComma), nCodePage);
else
{
while (nRow > nRowCurrent)
{
// Write new line
++nRowCurrent;
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
}
}
INT nColCurrent = 1;
BOOL bIsWriteCell = FALSE; // Нужно только для записи JSON-а
for (INT j = 0; j < pRow->m_arrItems.size(); ++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)
{
if (bJSON && FALSE == bIsWriteCell)
{
// Запишем пустые строки (для JSON-а)
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDoubleQuote, nCodePage);
}
// Write delimiter
++nColCurrent;
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sDelimiter, nCodePage);
bIsWriteCell = FALSE;
}
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.size())
{
OOX::Spreadsheet::CSi *pSi = static_cast<OOX::Spreadsheet::CSi *>(pSharedStrings->m_arrItems[nValue]);
if (NULL != pSi && pSi->m_arrItems.size() > 0)
if(NULL != pSi && pSi->m_arrItems.size() > 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 (bJSON || -1 != sCellValue.FindOneOf(sEscape))
{
sCellValue.Replace(sQuote, sDoubleQuote);
sCellValue = sQuote + sCellValue + sQuote;
}
// Write cell value
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sCellValue, nCodePage);
bIsWriteCell = TRUE;
}
if (bJSON)
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage);
}
if (bJSON)
{
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage);
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sEndJson, nCodePage, TRUE);
}
}
}
}
// Теперь мы пишем как MS Excel (новую строку записываем в файл)
if (!bJSON)
{
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage);
WriteFile(&oFile, &pWriteBuffer, nCurrentIndex, sNewLineN, nCodePage, TRUE);
}
RELEASEARRAYOBJECTS(pWriteBuffer);
oFile.CloseFile();
}
}
#ifndef CSV_WRITER
#define CSV_WRITER
#define CP_UTF16 1200
#define CP_unicodeFFFE 1201
#if defined(_WIN32) || defined (_WIN64)
#include <atlbase.h>
#include <atlstr.h>
#else
#include "../../Common/DocxFormat/Source/Base/ASCString.h"
#endif
#include "../../DesktopEditor/common/File.h"
#include "../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h"
namespace CSVWriter
{
void WriteFile(NSFile::CFileBinary *pFile, WCHAR **pWriteBuffer, INT &nCurrentIndex, CString &sWriteString, UINT &nCodePage, BOOL bIsEnd = FALSE);
void WriteFromXlsxToCsv(CString &sFileDst, OOX::Spreadsheet::CXlsx &oXlsx, UINT nCodePage, const WCHAR wcDelimiter, BOOL bJSON);
}
#endif //CSV_WRITER
This diff is collapsed.
This diff is collapsed.
// XlsxSerializerCom.cpp : Implementation of DLL Exports.
#include "stdafx.h"
#include "resource.h"
#include "ASCOfficeXlsxSerizer.h"
// The module attribute causes DllMain, DllRegisterServer and DllUnregisterServer to be automatically implemented for you
[ module(dll, uuid = "{E4E17295-6FF8-4bac-B4C2-E17D72111035}",
name = "XlsxSerializerCom",
helpstring = "XlsxSerializerCom 1.0 Type Library",
resource_name = "IDR_XLSXSERIALIZERCOM") ]
class CXlsxSerializerComModule
{
public:
// Override CAtlDllModuleT members
};
//Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define COMPONENT_NAME "XlsxSerializerCom"
#include "winres.h"
#include "version.h"
#include "../Common/FileInfo.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE 25, 1
#pragma code_page(1251)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION INTVER
PRODUCTVERSION INTVER
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "CompanyName", COMPANY_NAME
VALUE "FileDescription", FILE_DESCRIPTION_ACTIVEX
VALUE "FileVersion", STRVER
VALUE "InternalName", FILE_DESCRIPTION_ACTIVEX
VALUE "LegalCopyright", LEGAL_COPYRIGHT
VALUE "LegalTrademarks", COMPANY_NAME
VALUE "OriginalFilename", COMPONENT_FILE_NAME_DLL
VALUE "ProductName", FILE_DESCRIPTION_ACTIVEX
VALUE "ProductVersion", STRVER
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1252
END
END
#endif // !_MAC
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_PROJNAME "XlsxSerializerCom"
END
IDR_XLSXSERIALIZERCOM REGISTRY "XlsxSerializerCom.rgs"
////////////////////////////////////////////////////////////////////////////
#endif
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
HKCR
{
NoRemove AppID
{
'%APPID%' = s 'XlsxSerializerCom'
'XlsxSerializerCom.DLL'
{
val AppID = s '%APPID%'
}
}
}
This diff is collapsed.
This diff is collapsed.
// stdafx.cpp : source file that includes just the standard includes
// AVSOfficeDocxFile2.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef STRICT
#define STRICT
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#endif
#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _CRT_SECURE_NO_DEPRECATE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
// turns off ATL's hiding of some common and often safely ignored warning messages
#define _ATL_ALL_WARNINGS
#include <windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <atlcoll.h>
using namespace ATL;
#include "../Common/ASCUtils.h"
#include "../Common/Config.h"
#include <Gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
#import "../Redist/ASCFontConverter.dll" named_guids raw_interfaces_only rename_namespace("Fonts")
#pragma once
//1
//0
//1
//122
#define INTVER 1,0,1,122
#define STRVER "1,0,1,122\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