Skip to content

Commit

Permalink
改为对象类型API
Browse files Browse the repository at this point in the history
  • Loading branch information
mensong committed Nov 13, 2023
1 parent c2f5ea1 commit 5485b12
Show file tree
Hide file tree
Showing 6 changed files with 871 additions and 841 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/xlnt
/iKXiao/x64
/Test_iKXiao/x64
/Test_iKXiao/tmp
/iKXiao/tmp
148 changes: 126 additions & 22 deletions Test_iKXiao/Test_iKXiao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,140 @@
#include <iostream>
#include "..\iKXiao\iKXiao.h"

int main()
void normalTest()
{
IK_WORKBOOK wb = iKXiao::Ins().OpenExcel("E:\\admin.xlsx", NULL);

size_t rowCount = iKXiao::Ins().GetRowCount(wb, IDX_SHEET_CUR);
for (size_t r = 0; r < rowCount; r++)
WorkBook* wb = iKXiao::Ins().OpenExcel("admin.xlsx", NULL);
if (wb)
{
size_t columnCount = 0;
char* rowData = iKXiao::Ins().GetRowStringArray(wb, IDX_SHEET_CUR, r, &columnCount);
size_t offset = 0;
for (size_t c = 0; c < columnCount; c++)
WorkSheet* sheet = wb->OpenCurrentSheet();
if (sheet)
{
std::cout << rowData + offset << ",";
offset += strlen(rowData + offset) + 1;
size_t rowCount = sheet->GetRowCount();
for (size_t r = 0; r < rowCount; r++)
{
size_t columnCount = 0;
char* rowData = sheet->GetRowStringArray(r, &columnCount);
size_t offset = 0;
for (size_t c = 0; c < columnCount; c++)
{
std::cout << rowData + offset << ",";
offset += strlen(rowData + offset) + 1;
}
sheet->FreeString(rowData);
std::cout << std::endl;
}

Cell* cell = sheet->OpenCell(0, 0);
if (cell)
{
cell->SetStringValue("我爱你mensong");
std::string cellstr = cell->GetStringValue("");
std::cout << "(0,0) = " << cellstr << std::endl;
sheet->CloseCell(cell);
}


cell = sheet->OpenCell("A1");
if (cell)
{
std::string cellstr = cell->GetStringValue("");
std::cout << "A1 = " << cellstr << std::endl;
sheet->CloseCell(cell);
}

cell = sheet->OpenCell("A2");
if (cell)
{
cell->SetFormula("=SUM(1,2,3)");
int intVal = cell->GetIntValue(0);
std::cout << "=SUM(1,2,3) = " << intVal << std::endl;
sheet->CloseCell(cell);
}

wb->CloseSheet(sheet);
}
iKXiao::Ins().FreeString(wb, rowData);
std::cout << std::endl;

wb->Save("admin1.xlsx");

iKXiao::Ins().CloseExcel(wb);
}
}

char* cellStr = iKXiao::Ins().GetCellStringValue(wb, IDX_SHEET_CUR, 0, 0);
char* cellStr1 = iKXiao::Ins().GetCellStringValueByRefName(wb, IDX_SHEET_CUR, "A1");
void testConfig()
{
WorkBook* wb = iKXiao::Ins().OpenExcel("config.xlsx", NULL);
if (wb)
{
WorkSheet* sheet = wb->OpenCurrentSheet();
if (sheet)
{
size_t idxRowStart = sheet->GetNotEmptyRowStart();
size_t idxRowEnd = sheet->GetNotEmptyRowEnd();
size_t idxColumnStart = sheet->GetNotEmptyColumnStart();
size_t idxColumnEnd = sheet->GetNotEmptyColumnEnd();
for (size_t r = idxRowStart; r <= idxRowEnd; r++)
{
for (size_t c = idxColumnStart; c <= idxColumnEnd; c++)
{
Cell* cell = sheet->OpenCell(r, c);
if (cell)
{
auto type = cell->GetValueType();
switch (type)
{
case Cell::empty_value:
std::cout << "<NULL>" << ',';
break;
case Cell::boolean_value:
std::cout << cell->GetBoolValue() << ',';
break;
case Cell::date_value:
{
int year = 0;
int month = 0;
int day = 0;
cell->GetDateValue(year, month, day);
std::cout << year << "" << month << "" << day << "" << ',';
break;
}
case Cell::error_value:
std::cout << "#VALUE!" << ',';
break;
case Cell::inline_string_value:
case Cell::shared_string_value:
std::cout << cell->GetStringValue() << ',';
break;
case Cell::number_value:
std::cout << cell->GetDoubleValue() << ',';
break;
case Cell::formula_string_value:
std::cout << cell->GetDoubleValue() << ',';
break;
default:
std::cout << cell->GetStringValue() << ',';
break;
}

sheet->CloseCell(cell);
}
}
std::cout << std::endl;
}

iKXiao::Ins().SetCellStringValue(wb, IDX_SHEET_CUR, 0, 0, "我爱你mensong");
iKXiao::Ins().SetCellFormula(wb, IDX_SHEET_CUR, 0, 1, "=SUM(1,2,3)");
auto type = iKXiao::Ins().GetCellType(wb, IDX_SHEET_CUR, 0, 1);
char* formulaValue = iKXiao::Ins().GetCellStringValue(wb, IDX_SHEET_CUR, 0, 1);
wb->CloseSheet(sheet);
}

iKXiao::Ins().SaveExcel(wb, "E:\\admin1.xlsx", NULL);
iKXiao::Ins().CloseExcel(wb);
}
}

int main()
{
normalTest();

std::cout << std::endl << std::endl;

testConfig();

iKXiao::Ins().CloseExcel(wb);
return 0;
}
14 changes: 14 additions & 0 deletions Test_iKXiao/Test_iKXiao.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IntDir>tmp\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IntDir>tmp\$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IntDir>tmp\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IntDir>tmp\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down
Loading

0 comments on commit 5485b12

Please sign in to comment.