Aspose Cell Java - Splitting Cell Horizontally - aspose

How do i fit values in those horizontally splitted cells ? I am cloning each row dynamically. The values being populated currently is a merge field as i was using this approach but i couldn't make the report dynamic with it.
Any help would be appreciated.

Well, you cannot input two values in a single cell in MS Excel. I think You may achieve your task by merging/ un-merging some cells and input values into relevant cells accordingly. See the sample code below for your reference, it covers and design some part of your attached table/matrix. Please refer to it and you may write your own code (via Aspose.Cells APIs) to accomplish your task accordingly:
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
//Input header value to B1 cell (later we will merge it: B1:C1 --> B1
worksheet.Cells[0, 1].PutValue("header2");
//Input value to B2 cell that would be merged with B3 to become B2.
worksheet.Cells[1, 1].PutValue(1);
//Input value to C2 cell.
worksheet.Cells[1, 2].PutValue(2);
//Input value to C3 cell.
worksheet.Cells[2, 2].PutValue(3);
//Set row heights for 2nd and third rows for the cells accordingly.
worksheet.Cells.SetRowHeight(1, 25);
worksheet.Cells.SetRowHeight(2, 25);
//Merging cells.
//Merge B1:C1 --> B1
worksheet.Cells.Merge(0, 1, 1, 2);
//Merge B2:B3 --> B2
worksheet.Cells.Merge(1, 1, 2, 1);
//Formatting cells and ranges.
//Creating a range that spans over the all data cells of a worksheet
var range = worksheet.Cells.CreateRange("B1", "C3");
//Create a Style object.
Style colstyle = workbook.CreateStyle();
colstyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
colstyle.HorizontalAlignment = TextAlignmentType.Center;
StyleFlag flag = new StyleFlag();
flag.Borders = true;
flag.HorizontalAlignment = true;
//Apply the style to the range
range.ApplyStyle(colstyle, flag);
workbook.Save("e:\\test2\\output__mergedcells.xlsx");
See the screen shot of the output Excel file taken in Ms Excel for your reference:
http://prntscr.com/8rbc0i
I am a developer/evangelist at Aspose.

Related

Subtracting from total if adjacent cell has content

I'm looking to subtract from a total derived from the following:
Count the occurrences of the content in cell E2 =COUNTIF(B:B, E2)
I want to subtract 1 from that total IF an adjacent cell contains anything.
FOr example:
B2 has content == E2, and C2 is NOT empty, subtract 1 from total
B3 has content == E2, and C3 is empty
B4 has content == E2, and C4 is NOT empty, subtract 1 from total
The end result would be =COUNTIF(B:B, E2)-2.
This seemed kind of ridiculous to explain in text so here is an example worksheet with a column expressing where I would like to see the formula, and a column with the expected output. Programatically this would be a very simple task, but doing it in a spreadsheet is new to me. I'm hoping this can be done.
https://docs.google.com/spreadsheets/d/15xEEyeJx1atsZiDDwCk57KfnbCcZbIavV-gyVF0xuCA/edit?usp=sharing
Also, column A and B can vary in length, so I would prefer something that adapts to the length of the column.
delete range D:F
use in D2:
=ARRAYFORMULA(QUERY(QUERY({B1:B,
IF((B1:B<>C1:C)*(A1:A<>"")*(C1:C=""), 1, 0)},
"select Col1,count(Col1),sum(Col2)
where Col1 !=''
group by Col1"),
"offset 1", 0))

subtracting time values from columns

Sup, simple question ( i hope). I am adding a custom column in Power bi. I need to subtract time values, using custom column formula. Problem: (B-A)-C causes error.
Values are set to time type.
B = 15.00.00
A = 9.00.00
C = 0.05.00
custom column formula:
=([B]-[A])-[C]
Result i want: 5.55.55
Result i get:
Expression.Error: We cannot apply operator - to types Duration and Time.
Details:
Operator=-
Left=0.06:00:00
Right=0.05.00
So B-A = 0.06:00:00 and therefore 0.06:00:00 - 0.05.00 = error. I need to get B-A result in shape of 06.00.00 so i can subtract value C from it. Any suggestions?
Assuming your table is called "Table":
First, create a new column and calculate the difference of B and A.
Col1 = DATEDIFF(Table1[B],Table1[A],HOUR)
Then create another column and subtract C from it.
Col2 = DATEDIFF(Table1[Col1],Table1[C],HOUR)

c++ qt range of excel querySubObject

I try to write Data from Qt into an excel-File. I found this piece of code letting me write my Data into an 5*5 range.
//get a 5x5 range of cells : from A1 to E5
QAxObject *range = sheet1->querySubObject( "Range(const QString&, const QString&)", QString("A1"), QString("f5"));
QVariant vTable(table);
range->dynamicCall("SetValue(const QVariant&)", vTable);
My data is much bigger than 5 colums and 5 rows and varies in size. Is there a possibility of setting the range with numbers something like:
QAxObject *range = sheet1->querySubObject( "Range(7,123)");
meaning my data should have the size of 7 columns and 123 rows ?
Thanks very much for your answers
Itelly
If your data is 123x7 table then you can initialize your range as
QAxObject *range = sheet1->querySubObject( "Range(A1,G123)");
Assuming that you are storing your values in vTable then you can call :
range->dynamicCall("setValue(const QVariant&)",vTable);
to put your values to spreadsheet.

SAS/IML: how to use individual variance components in RANDNORMAL

This is a programming question, but I'll give you a little of the stats background first. This question refers to part of a data sim for a mixed-effects location scale model (i.e., heterogeneous variances). I'm trying to simulate two MVN variance components using the RANDNORMAL function in IML. Because both variance components are heterogeneous, the variances used by RANDNORMAL will differ across people. Thus, I need IML to select the specific row (e.g., row 1 = person 1) and use the RANDNORMAL function before moving onto the next row, and so on.
My example code below is for 2 people. I use DO to loop through each person's specific variance components (VC1 and VC2). I get the error: "Module RANDNORMAL called again before exit from prior call." I am assuming I need some kind of BREAK or EXIT function in the DO loop, but none I have tried work.
PROC IML;
ColNames = {"ID" "VC1" "VC2"};
A = {1 2 3,
2 8 9};
PRINT A[COLNAME=ColNames];
/*Set men of each variance component to 0*/
MeanVector = {0, 0};
/*Loop through each person's data using THEIR OWN variances*/
DO i = 1 TO 2;
VC1 = A[i,2];
VC2 = A[i,3];
CovMatrix = {VC1 0,
0 VC2};
CALL RANDSEED(1);
U = RANDNORMAL(2, MeanVector, CovMatrix);
END;
QUIT;
Any help is appreciated. Oh, and I'm using SAS 9.4.
You want to move some things around, but mostly you don't want to rewrite U twice: you need to write U's 1st row, then U's 2nd row, if I understand what you're trying to do. The below is a bit more efficient also, since I j() the U and _cv matrices rather than constructing then de novo every time through the loop (which is slow).
proc iml;
a = {1 2 3,2 8 9};
print(a);
_mv = {0,0};
U = J(2,2);
_cv = J(2,2,0);
CALL RANDSEED(1);
do i = 1 to 2;
_cv[1,1] = a[i,2];
_cv[2,2] = a[i,3];
U[i,] = randnormal(1,_mv, _cv);
end;
print(u);
quit;
Your mistake is the line
CovMatrix = {VC1 0, 0 VC2}; /* wrong */
which is not valid SAS/IML syntax. Instead, use #Joe's approach or use
CovMatrix = (VC1 || 0) // (0 || VC2);
For details, see the article "How to build matrices from expressions."
You might also be interested in this article that describes how to carry out this simulation with a block-diagonal matrix: "Constructing block matrices with applications to mixed models."

Multi-row text in heading

I'm working on a complex grid layout, and UltimateGrid is my choice.
I have set a multi-row heading, then I have joined some cells in heading vertically.
Now, I'm looking for a way to set multi-line text in heading cells which I have joined.
Here's an explanatory screenshot.
I already have tried by writing:
void MyCug::OnSetup(){
int rows = 5;
int cols = 20;
// setup rows and columns
SetNumberRows(rows);
SetNumberCols(cols);
// create 3 row top heading
SetTH_NumberRows(2);
...
JoinCells (16, -2, 16, -1); // Here I joins - in heading - two cells : row 16, columns -2 and -1
...
// Then I retrieve merged cell
CUGCell m_cell;
GetCell(16, -2, &m_cell);
// I need to show multi-line content in heading cells: I tried to set multi-row property.
int result = m_cell.SetPropertyFlags(m_cell.GetPropertyFlags() | UGCELL_MULTIROWCELL);
if (result == UG_SUCCESS) {
bool ok = true; // all seems to be ok...
}
m_cell.SetText("string\r\nstring\r\nstring"); // Despite my attempt, this will be always show on a single line!
SetCell(16, -3, &m_cell);
...
}
Without success: cell text is always shown on a single line, that is exactly what I don't want.
How can I get the cell text on multiple lines?
I tell how I have solved my problem, hoping it will be useful to someone.
To set multi-line cells, member function CUGCell::SetCellTypeEx() should be used.
This function allow you to set extended properties for single cells.
The example below works perfectly:
void MyCug::OnSetup(){
int rows = 5;
int cols = 20;
// setup rows and columns
SetNumberRows(rows);
SetNumberCols(cols);
// create 3 row top heading
SetTH_NumberRows(2);
...
JoinCells (16, -2, 16, -1); // Here i joins - in heading - two cells : row 16, columns -2 and -1
...
// I retrieve merged cell
CUGCell m_cell;
GetCell(16, -2, &m_cell);
cell.SetCellTypeEx(UGCT_NORMALMULTILINE); // set multiline cell
m_cell.SetText("string\r\nstring\r\nstring");
SetCell(16, -3, &m_cell);
}
Inside the OnSetup() method:
Set the number of rows in the top heading.
SetTH_NumberRows(2); // Set 2 rows
Join the range of cells together
JoinCells(1,-2, 1,-1); // Join row -1 and -2 in column 1
Add multiline feature to the cell
QuickSetCellTypeEx(1, -2, UGCT_NORMALMULTILINE); // Column 1, row -2 is a multiline
Add text
CString title = _T("New\r\nline");
QuickSetText(1, -2, title); SetColWidth(1, 200); // Set text in the preferred cell