In LibreOffice Basic, how to condition for a non-empty string variable - libreoffice

I recently started using Macros in Libreoffice Calc and stumbled upon a quite basic problem, I simply can't find a solution to. I want to check if a string variable is non-empty in an if ... then condition
Currently in a Macro for Libreoffice Calc the code reads in 6 cells as variables
for I = 1 to 6
column(I) = oDoc.Sheets.getByName(K).getCellByPosition(I-1,J).String 'read column 1-6
next I
checks for some conditions
if column(4) = "" OR column(5) = "" OR column(6) != "" then
then writes those strings into new cells.
for I = 1 to 6
oDoc.Sheets.getByName("evalution").getCellByPosition(I,currentline+2).setString(column(I))
next I
if the conditions are not meat an else ... then moves the read entries somewhere else and writes them down there. By working in a loop of increasing J per sheet K and working trough all sheets K I can go trough the whole document an paste the lines with those 6 entries in a sorted in the evalution sheet.
If cells are empty, then when read the string is also just empty so I can check with = "".
But I can't find any way to check if the cell was not empty, so the string has anything in it and is not null.
I tried with a simple NOT condition so column(6) NOT = "" then, but no matter where I would place the NOT, LibreOffice always spits out an error. I tried using != like in the example as another way to negate the condition. Then the other way around tried if I could use = "*" or = "\w" as placeholder for any character. Nothing worked.
After also googling quite a bit and finding nothing to my problem, I turn to the hivemind of the internet itself, if anyone can help me.

Related

Getting numbers separate from letters from a field in Crystal Reports SAP when the format changes

I'm sorry if this has already been solved, I cant seem to find anything for my specific issue.
We have job numbers that use the following formats: 011111, 11111A, and 11A111. For all of these, I need to export to a new field that just reads 11111. I know I can use right({table.job},5) for the first, left({table.job},5) for the second, or even val({table.job}) but I can not find anything that works to get just the numbers out of the last format.
I have tried using val({table.job}) but it only gives me the first set before the letter. I have tried using the join function and using left 2 + right 3, but I'm still new to this and I'm not certain that I have been using the correct syntax.
I also tried using an array to find the third character to see if it was a specific letter, but it is not accepting the code, and I scrapped it.
When I typed all of it out, I kept getting the error "The ) is missing" but no words were highlighted and I have double checked the opening and closing parenthesis. I know it might be something simple, but I am stumped. Any ideas?
Here's one possible solution:
local stringvar JobN := "011A111";
local stringvar result := "";
local numbervar i;
For i := 1 to Len(JobN) do
(IF isnumeric(JobN[i]) Then result := result + JobN[i]) ;
ToText(Val(result),0,"");

Xlsread sheet in for loop

I have a number of excel sheets I would like to cycle through enclosed in a for loop, with sheet name a through A to X. Is this possible?
I tried this:
for letter='A':'X'
[num,txt,raw] = xlsread('Grouting_sum_final.xlsx','%s',letter);
% Lots of code below here (not relevant for the problem)
end
Yes, it is, but you do not need the '%s' part of your line.
If you go to the documentation website, you will find that you have to pass as first argument the excel file name and as second the sheet name.
So your code should read something like:
for letter='A':'X'
[num,txt,raw] = xlsread('Grouting_sum_final.xlsx',letter);
% Lots of code below here (not relevant for the problem)
end
Also, I am assuming you are aware that you keep on overwriting your data retrieved from the Excel sheet.

matlab 'evidence removio': delete last shown command

I would like to remove whatever I just typed - and the last shown command - from the matlab console display. Needless to say, this would be ideal for pranksters (but this is of course strictly for academic purposes only). This is as far as I have gotten (based on this related answer):
hist = com.mathworks.mlservices.MLCommandHistoryServices.getSessionHistory; %get history
last = strjoin(cell(hist(end-2:end)),' '); %convert history to string
fprintf(repmat('\b',1,numel(last))); %replace characters of string with whitespace
However I can only access the last typed command (through the command history) - not the last displayed command (which would be ideal). Any ideas how to solve this?
Disclaimer: I don't advise doing this.
The MATLAB CommandWindow contents are stored as a CmdWinDocument, which is an extension of the Java PlainDocument type, and an interface of the Document type. The current window can be accessed using the command:
com.mathworks.mde.cmdwin.CmdWinDocument.getInstance
In theory, you should be able to remove text from the command window using something like:
doc = com.mathworks.mde.cmdwin.CmdWinDocument.getInstance
endpos = doc.getEndPosition
doc.remove(endpos-10,10)
which would, in theory, remove the last 10 character from the document. You may have to call the removeUpdate function as well. Obviously problems will be caused by the fact that these commands will be appended to the document during this process. I have not tested this, and you're likely to cause problems with internally stored offsets within the CmdWinDocument class, so use at your own risk.

Using PowerShell to modify MS Word cell borders

I routinely create reports using MS Word. Part of this report contains a table, which I have been copying manually from Excel into the word document. I am trying to use PowerShell in order to do this automatically, but I am having trouble finding the correct formatting commands. Specifically, I am currently trying to format the table so that every border between rows is dotted instead of solid, but the borders between columns are invisible. So something like this:
Heading1 Heading2 Heading3
.................................................
H1Item1 H2Item1 H3Item1
.................................................
H1Item2 H2Item2 H3Item2
.................................................
I did find that this gets me going in the right direction, but doesn't quite provide the granularity of border control that I'm looking for:
$Table.Range.Style = "Table Grid"
$Table.Borders.InsideLineStyle = 2
$Table.Borders.OutsideLineStyle = 0
If there is any good documentation on formatting Word paramters through PowerShell, I would really appreciate the pointer. I've managed to find articles relating to how to do specific things, but no good documentation.
Aha! I found it. I was trying for a way to do it in one line, but I found that if I just edit each row as I'm adding the data to it, then I can get the whole table that way. This is the line I added to my Foreach loop:
$Table.Rows($x).Borders.InsideLineStyle = 0
I would still love a link to some good documentation if anyone knows of any!

How do i open a number of xlsx files when I only know part of the filename in Matlab?

I am using Matlab 2013b. I have a list of excel files in a directory and I want to open chosen ones within a loop to read out the data.
I only know the start of each of the file names however, not the ending. I have a vector of numbers that provide the identifying portion of the file's name (filenumber), and I want to loop through the excel files one by one, opening them and extracting the data, then closing them.
There are 500 files, each of the format: img_****ff*******.xlsx, where the first set of asterisks is my filenumber, while the second set of asterisks is unknown.
So far, I have tried listing what is in the directory using:
list=dir('E:\processed\Img*');
filenames={list.name}
This provides with with the full file names.
I tried then within a loop to create the part of the filename I know exists:
x = sprintf('Img_%d_FF_',img(1,1));
I then thought I could use 'Find' to look for my my partial filename/string in the 'filenames' structure above. I don't think I have the code correct for this datatype though:
index = find(strcmp({list.name}, x)==1)
You're pretty close, but the issue is that strcmp compares the whole string and since you only have the beginning part, it is not going to match. I would use strncmp to compare only the first n characters of the string. We can determine what n is based upon the length of your string x.
matches = strncmp({list.name}, x, numel(x));
thisfile = list(matches).name;