Can't get LibXL xlSheetGetNamedRange to work - excel

I am trying to work with LibXL. I can extract data from sheets, but need a function to transform a string with Excel row and column indices into startRow, endRow, startCol, endCol i.e.
"A1:B3" into startRow = 0, endRow = 2, startCol = 0, endCol = 1 (LibXL uses 0 based indexing)
I have tried everything I can think of. The library does not come with any examples that use this function and the documentation is quite sparse. What am I doing wrong?
Here is my code:
int main()
{
const char range[] = "B2:C3";
int i, ret, rowFirst=0, rowLast=0, colFirst=0, colLast=0;
BookHandle book;
SheetHandle sheet;
book = xlCreateBook();
ret = xlBookLoad(book, "/home/jason/Downloads/panel.xls");
sheet = xlBookGetSheet(book, 0);
ret = xlSheetGetNamedRange(sheet, &range[0], &rowFirst, &rowLast, &colFirst, &colLast);
printf("ret from xlSheet...Range = %d\n", ret);
printf("%s\n", xlBookErrorMessage(book));
printf("rowLast = %d\n", rowLast);
printf("rowLast = %d\n", rowLast);
printf("colFirst = %d\n", colFirst);
printf("colLast = %d\n", colLast);
return 0;
}

use xlSheetAddrToRowCol() function for this purpose:
int rowStart, colStart, rowEnd, colEnd;
int rowRelativeStart, colRelativeStart, rowRelativeEnd, colRelativeEnd;
xlSheetAddrToRowCol(sheet, "B2", &rowStart, &colStart, &rowRelativeStart, &colRelativeStart);
xlSheetAddrToRowCol(sheet, "C3", &rowEnd, &colEnd, &rowRelativeEnd, &colRelativeEnd);

Related

Developing Visual Studio Universal Project - How to extract text from sequential named TextBoxes in for loop

I have a problem with the following code which I thought would extract user input from sequential TextBoxes on a form:
#include "pch.h"
#include "MainPage.xaml.h"
#include <iostream> // for std::cout and std::cin
#include <sstream>
#include <string>
{
int grid[9][9] = { 0 }; // virtual array filled with zeros
//put numbers in array
for (int row = 0; row < 9; ++row)//step through all rows
for (int col = 0; col < 9; ++col) //step through all columns
{
row = row + 1; // text box names suffixes are 11 to 19
col - col + 1;
std::string r_str = std::to_string(row);// turn row number into text
std::string c_str = std::to_string(col);//turn column nuber into text
std::string texnum = "Tex" + r_str + c_str;// eg "Tex11" //compile textbox name
String^ str_input = texnum->Text; //get Platform::String from textBox
std::wstring wsstr(str_input->Data());//Convert Platform::String to String
int n = std::stoi(wsstr);//Convert String to Integer
grid[row][col] = n; //put text from texbox in array as a number
}
}
On the line
String^ str_input = texnum->Text;
At the TexBox Identifier of texnum it gives an error of Expression must have a pointer or handle type. If I replace it with an actual Textbox name Tex11 there is no Error but then it only extract text from one box.
I need a way to get text from a TextBox using a string variable instead of the actual string.
Any help would be appreciated.
You can't directly use the string to try to get the Text property, in that case, it is only a string instead of TextBox object. So you need to first get the TextBox control by the name string you get and then get the Text property by the TextBox.
You can try the following code to use the FindName method to get the TextBox object, the "MyPage" is the parent view of TextBox(e.g. StackPanel). In addition, the FindName method needs to be passed the PlatForm::String^ type, it's easy to convert std::wstring to PlatForm::String^, so it's better to only use std::wstring type instead of std::string.
int grid[9][9] = { 0 }; // virtual array filled with zeros
//put numbers in array
for (int row = 0; row < 9; ++row)//step through all rows
for (int col = 0; col < 9; ++col) //step through all columns
{
row = row + 1; // text box names suffixes are 11 to 19
col - col + 1;
std::wstring r_str = std::to_wstring(row);// turn row number into text
std::wstring c_str = std::to_wstring(col);//turn column nuber into text
std::wstring texnum = L"texnum" + r_str + c_str;
Platform::String^ aa = ref new Platform::String(texnum.c_str());
TextBox^ elment = (TextBox ^)MyPage->FindName(ref new Platform::String(texnum.c_str()));
String^ str_input = elment->Text;
std::wstring wsstr(str_input->Data());
int n = std::stoi(wsstr);
}
Here is my final code (The StackPanel is named FirstLine)
void universal::MainPage::Solve_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
int grid[9][9] = { 0 }; // virtual array filled with zeros
//put numbers in array
for (int row = 0; row < 9; ++row)//step through all rows
for (int col = 0; col < 9; ++col) //step through all columns
{
row = row + 1; // text box names suffixes are 11 to 19
col = col + 1;
std::wstring r_str = std::to_wstring(row);// turn row number into text
std::wstring c_str = std::to_wstring(col);//turn column nuber into text
std::wstring texnum = L"texnum" + r_str + c_str;
Platform::String^ aa = ref new Platform::String(texnum.c_str());
TextBox^ elment = (TextBox^)FirstLine->FindName(aa);
String^ str_input = elment->Text;
std::wstring wsstr(str_input->Data());
int n = std::stoi(wsstr);
}

Custom kernel isn't printing on the screen correctly

I'm having trouble getting strings to print on my custom kernel. I've been following a tutorial on github. So far, I can only print strings that are 5 characters or less, and can't directly pass a string as a parameter.
kernel.c
#include "../drivers/screen.h"
void main() {
clear_screen();
// This line does NOT work.
kprint_at("X", 10, 10);
// This line DOES work
char msg[] = "X";
kprint_at(msg, 10, 10);
// This line does NOT work
char msg[] = "123456"; // Will only work for strings less than 6 characters.
kprint_at(msg, 10, 10);
}
screen.c
void kprint_at(char* message, int col, int row) {
int offset;
if (col >= 0 && row >= 0) offset = get_offset(col, row);
else {
offset = get_cursor_offset();
row = get_offset_row(offset);
col = get_offset_col(offset);
}
int i = 0;
while (message[i] != 0) {
offset = print_char(message[i++], col, row, WHITE_ON_BLACK);
row = get_offset_row(offset);
col = get_offset_col(offset);
}
}
int print_char(char c, int col, int row, char attr) {
unsigned char* vidmem = (unsigned char*) VIDEO_ADDRESS;
if (!attr) attr = WHITE_ON_BLACK;
if (col >= MAX_COLS || row >= MAX_ROWS) {
vidmem[2*(MAX_COLS)*(MAX_ROWS)-2] = 'E';
vidmem[2*(MAX_COLS)*(MAX_ROWS(-1] = RED_ON_WHITE;
return get_offset(col, row);
}
int offset;
if (col >= 0 && row >= 0) offset = get_offset(col, row);
else offset = get_cursor_offset();
if (c == '\n') {
row = get_offset_row(offset);
offset = get_offset(0, row+1);
} else {
vidmem[offset] = c;
vidmem[offset+1] = attr;
offset += 2;
}
set_cursor_offset(offset);
return offset;
}
If i set the row or col to beyond the width or height of the screen, I do get a red E at the bottom right corner, so I know that's working properly. Also, if I set the word to start near the end of the screen, it continues on the next line. It just won't let me input the string directly into the kprint_at function, and won't let me use any strings greater than 5 characters. Any ideas on whats going on?
I am using c language, with assembly. I'm also using a 64-bit linux system, but I'm running my kernel in 32-bit protected mode. Using a gcc cross compiler (i386-elf-gcc).

How get string from skip in DOORS DXL

I am using following code to get string from skip function. But i am getting integer numbers. I will appreciate if someone can help me out.
int csvToSkip(string csv, Skip skip, char delimeter)
{
int i = 0
int j = 0
int index = 0
for (i = 0; i < length(csv); i++)
{
if (csv[i] == delimeter)
{
put(skip, 0, "1")
j = i + 1
}
else if (i == length(csv) - 1)
{
put(skip, 1, "2")
}
}
return(index)
}
Skip mySkip=create;
string test="hi this is test;for another test";
char delimiter =';';
int x=csvToSkip(test, mySkip, delimiter );
print x;
for sValue in mySkip do
{
print (int key mySkip) " " sValue "\n";
}
This gives me following result
0
0 204534013
1 204534015
You did not declare sValue, so DXL guessed wrongly what data type the values have.
The first chapter of DXL Manual -> Language fundamentals, called "Auto-Declare", explains how you can disable the auto-declare functionality. If you do this, DOORS will warn you when you access undeclared variables.

CString + operator or Format

I have a sample code like this:
CString A = _T("abc");
CString B = _T("xyz");
CString res;
now to concat these two above strings, which one should I prefer:
res = A + _T(" ") + B;
or
res.Format(_T("%s %s"), A, B);
Made a sample function and ran the the bellow code
CString str1 = _T("abc");
CString str2 = _T("xyz");
CString strRes;
DWORD dwTickCount = GetTickCount();
const int LoopCount = 1000000;
for(int nIdx = 0; nIdx < LoopCount; nIdx++)
{
strRes = str1 + _T(" ") + str2;
}
dwTickCount = GetTickCount() - dwTickCount;
The value of dwTickCount was 2656. But while checking the second case,
CString str1 = _T("abc");
CString str2 = _T("xyz");
CString strRes;
DWORD dwTickCount = GetTickCount();
const int LoopCount = 1000000;
for(int nIdx = 0; nIdx < LoopCount; nIdx++)
{
strRes.Format(_T("%s %s"), str1, str2);
}
dwTickCount = GetTickCount() - dwTickCount;
The value of dwTickCount was 453 only.
Hence I can say, the Format approach is about 6 times faster.

how to get partial string seperated by commas?

I have a string:
string mystring="part1, part2, part3, part4, part5";
How can I just return the first 3 elements without splitting them up first?
so like this:
string newstring="part1, part2, part3";
You could get the first three using:
RegEx r = new RegEx(#"(\S+, \S+, \S+), \S+");
I'm sure there is a better way to write the regex, but I think that would do it for basic inputs.
Try to find Index of 3rd Comma, and then get the substring.
Example
void Main()
{
string mystring="part1, part2, part3, part4, part5";
int thirdCommaIndex = IndexOf(mystring, ',', 3);
var substring = mystring.Substring(0,thirdCommaIndex-1);
Console.WriteLine(substring);
}
int IndexOf(string s, char c, int n)
{
int index = 0;
int count = 0;
foreach(char ch in s)
{
index++;
if (ch == c)
count++;
if (count == n )
break;
}
if (count == 0) index = -1;
return index;
}
This will parse the string trying to find the third comma and throwing it and everything after it away.
string mystring = "part1, part2, part3, part4, part5";
UInt16 CommasFound = 0;
UInt16 Location = 0;
for (Location = 0; (CommasFound < 3) &&
(Location < mystring.Count()); Location++)
if (mystring[Location].Equals(','))
CommasFound++;
if (CommasFound == 3)
{
string newstring = mystring.Substring(0, Location-1);
}
else { // Handle the case where there isn't a third item
}

Resources