wxAutoExcel 2.0.0 Small example using Visual Studio 2022

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
carlosrnardi
In need of some credit
In need of some credit
Posts: 2
Joined: Thu Dec 31, 2020 4:32 pm

wxAutoExcel 2.0.0 Small example using Visual Studio 2022

Post by carlosrnardi »

This small example show how to configure Visual Studio to use the wxAutoExcel library. *In this example I´m using static libraries.

Follow the steps to create a project, If You need to compile the wxAutoExcel static libraries, follow these steps from here viewtopic.php?f=29&t=49419

Creating a project

01 - Create an empty project.
Image

Image

02 - Create cApp class files

cApp.h

Code: Select all

#pragma once
#pragma comment( lib, "wxAutoExcel20.lib" )

#include "wx/wx.h"
#include "wx/wxAutoExcel.h"

class cApp : public wxApp
{
public:
	cApp() = default;
	~cApp() = default;

	virtual bool OnInit();
};
cApp.cpp

Code: Select all

#include "cApp.h"
using namespace wxAutoExcel;

wxIMPLEMENT_APP(cApp);

bool cApp::OnInit()
{

    wxExcelApplication app = wxExcelApplication::CreateInstance();

    if (!app)
    {
        wxLogError(_("Could not launch Microsoft Excel. Please check that it is properly installed."));
    }

    wxExcelWorkbook workbook = app.GetWorkbooks().Add();
    if (!workbook)
    {
        wxLogError(_("Failed to create a new workbook."));
    }

    wxExcelRange range = workbook.GetWorksheets()[1].GetRange("A1");
    range = "Hello, World!";
    range.GetFont().SetColor(*wxBLUE);

    app.SetVisible(true);

	return true;
}
03 - Linker / System - Subsystem - (/SUBSYTEM:WINDOWS)
Make sure the SubSystem configuration is configured as SUBSYSTEM:WINDOWS for all configuration types.

04 - Add library path to include directory list
Add this wxAutoExcel library path to the directory list - $(WXWIN)\include;$(WXWIN)\include\msvc;$(WXEXCEL)\include
in the example above the WXWIN environment variable is related to the wxWidgets path.
Image

05 - Add library path for each Configuration x Platform type.
  • x64 - $(WXWIN)\lib\vc_x64_lib;$(WXEXCEL)\out\build\x64\lib
  • x64 Debug - $(WXWIN)\lib\vc_x64_lib;$(WXEXCEL)\out\build\x64-Debug\lib
  • x86 - $(WXWIN)\lib\vc_lib;$(WXEXCEL)\out\build\x86\lib
  • x86 Debug - $(WXWIN)\lib\vc_lib;$(WXEXCEL)\out\build\x86-Debug\lib
Image

Image

Hope that helps!
Post Reply