//ClosedXML C++/CLIでxlsxファイルの読み書き #include #include #include using namespace System; extern "C" { __declspec(dllexport) int opnbook(char * string01); __declspec(dllexport) int opnsheet(char * string01); __declspec(dllexport) char * rcell(int y1,int x1,char * string01); __declspec(dllexport) char * rcellu(int y1,int x1,char * string01); __declspec(dllexport) char * rcellfx(int y1,int x1,char * string01); __declspec(dllexport) int wcellval(int y1,int x1,int int01); __declspec(dllexport) int wcellstr(int y1,int x1,char * string01); __declspec(dllexport) int wcellstru(int y1,int x1,char * string01); __declspec(dllexport) int wcellfx(int y1,int x1,char * string01); __declspec(dllexport) int cellattr( int y1, int x1, int h1, int w1, char * string01, int size1, int r1, int g1, int b1, int r2, int g2, int b2, int valign, int halign); __declspec(dllexport) int cellmrg( int y1, int x1, int y2, int x2); __declspec(dllexport) int setprint(int y1, int x1, int y2, int x2, int size1, int orient1, int top1, int bottom1, int left1, int right1, int header1, int footer1); __declspec(dllexport) int savebook(char * string01); __declspec(dllexport) int clssheet(); __declspec(dllexport) int clsbook(); int ret= 0; unsigned int n = 0; char * param1; gcroot cls; int loadcsdll() { cls = gcnew excelcs001::excelcs001(); return cls->opnbook( (LPWSTR)param1); } int opnbook(char * string01) { n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0 ); param1 = (char *)calloc(1,n*2 + 2); MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n+1 ); try { ret = loadcsdll(); free(param1); return ret; } catch (Exception^ e) { printf("%s\r\n", e->Message); free(param1); return -2; } } int opnsheet(char * string01) { n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0 ); param1 = (char *)calloc(1,n*2 + 2); MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n+1 ); ret = cls->opnsheet( (LPWSTR)param1); free(param1); return ret; } char * rcell(int y1,int x1,char * string01) { char * ret01 = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(cls->rcell( y1,x1)).ToPointer(); unsigned int len = strlen(string01); n = strlen(ret01); if (len>=n+1) { strcpy(string01,ret01); } else { * string01='\0'; } System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)ret01); return string01; } char * rcellu(int y1,int x1,char * string01) { wchar_t * ret01 = (wchar_t *)System::Runtime::InteropServices::Marshal::StringToHGlobalUni(cls->rcell( y1,x1)).ToPointer(); n = WideCharToMultiByte(CP_UTF8, 0, ret01, -1, NULL, 0, NULL, NULL); param1 = (char *)calloc(1,n + 1); WideCharToMultiByte(CP_UTF8, 0, ret01, -1, param1, n+1, NULL, NULL); unsigned int len = strlen(string01); n = strlen(param1); if (len>=n+1) { strcpy(string01,param1); } else { * string01='\0'; } System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)ret01); free(param1); return string01; } char * rcellfx(int y1,int x1,char * string01) { char * ret01 = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(cls->rcellfx( y1,x1)).ToPointer(); unsigned int len = strlen(string01); n = strlen(ret01); if (len>=n+1) { strcpy(string01,ret01); } else { * string01='\0'; } System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)ret01); return string01; } int wcellval(int y1,int x1,int int01) { ret = cls->wcellval( y1, x1, int01); return ret; } int wcellstr(int y1,int x1,char * string01) { n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0 ); param1 = (char *)calloc(1,n*2 + 2); MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n+1 ); ret = cls->wcellstr( y1, x1, (LPWSTR)param1); free(param1); return ret; } int wcellstru(int y1,int x1,char * string01) { n = MultiByteToWideChar( CP_UTF8, 0, string01, -1, NULL, 0); param1 = (char *)calloc( 1,n*2 + 2); MultiByteToWideChar( CP_UTF8, 0, string01, -1, (LPWSTR)param1, n+1); ret = cls->wcellstr( y1, x1, (LPWSTR)param1); free(param1); return ret; } int wcellfx(int y1,int x1,char * string01) { n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0 ); param1 = (char *)calloc(1,n*2 + 2); MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n+1 ); ret = cls->wcellfx( y1, x1, (LPWSTR)param1); free(param1); return ret; } int cellattr( int y1, int x1, int h1, int w1, char * string01, int size1, int r1, int g1, int b1, int r2, int g2, int b2, int valign, int halign) { n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0 ); param1 = (char *)calloc(1,n*2 + 2); MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n+1 ); ret = cls->cellattr( y1, x1, h1, w1, (LPWSTR)param1, size1, r1, g1, b1, r2, g2, b2, valign, halign); free(param1); return ret; } int cellmrg( int y1, int x1, int y2, int x2) { ret = cls->cellmrg( y1, x1, y2, x2); return ret; } int setprint(int y1, int x1, int y2, int x2, int size1, int orient1, int top1, int bottom1, int left1, int right1, int header1, int footer1) { ret = cls->setprint( y1, x1, y2, x2, size1, orient1, top1, bottom1, left1, right1, header1, footer1); return ret; } int savebook(char * string01) { n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0 ); param1 = (char *)calloc(1,n*2 + 2); MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n+1 ); ret = cls->savebook( (LPWSTR)param1); free(param1); return ret; } int clssheet() { ret = cls->clssheet(); return ret; } int clsbook() { ret = cls->clsbook(); return ret; } }