PHPExcel setRowHeigt -1 - height

I use phpoffice/phpexcel and I have problem with autofit row height.
I've found I should use:
$height = -1;
$sheet->getStyle("B$rowNum")->getAlignment()->setWrapText(true);
$sheet->getRowDimension($rowNum)->setRowHeight($height);
It doens't work for me. But if I set $height = 40; it works correctly.
I've found in PHPExcel_Worksheet_RowDimension class method setRowHeight:
class PHPExcel_Worksheet_RowDimension
{
[...]
private $_rowHeight = -1;
[...]
public function setRowHeight($pValue = -1) {
$this->_rowHeight = $pValue;
return $this;
}
[...]
}
So - actually -1 is default value for row height and defaultly row height isn't fitted.
Can anyone help me?

-1 is the default height: but there isn't an autosize for row height in there is for column widths. It's not a function that MS Excel provides, so it isn't done in PHPExcel either. You can only set a row height to a specific dimension, or tell it to apply the default.

Related

FLTK Setting width of display area of slider value

I was wondering how to change the width of the area responsible for showing the current value of a Fl_Hor_Value_Slider. The thing is, I want to be able to select a year (that's 4 digits) and the space on the side of the slider is not enough to display the year number correctly.
I've looked through the docs and tried the following functions:
slider_size()
maximum()
minimum()
range()
But they don't seem do do what I want.
I feel as though I've missed something obvious.
Any ideas?
The problem is that the size is hardcoded to 35 for horizontal or 25 for vertical. You need to modify Fl_Value_Slider.cxx. In the routine draw, it has
if (horizontal()) {
bww = 35; sxx += 35; sww -= 35;
} else {
syy += 25; bhh = 25; shh -= 25;
}
This is based on a textsize_ of 10. If you change the text size, then it needs to go up based on the text size. Something like
if (horizontal()) {
int width = textsize() * 3 + 5;
bww = width; sxx += width; sww -= width;
} else {
int height = textsize() * 2 + 5;
syy += height; bhh = height; shh -= height;
}
Then rebuild the fltk library. Either keep this patch or send it to FLTK and check whenever you get an update from FLTK. To test
Fl_Hor_Value_Slider* o = new Fl_Hor_Value_Slider(10, 50, 250, 50, "");
o->tooltip("Value Slider");
o->selection_color((Fl_Color)1);
o->textsize(25);
o->value(2000)
o->range(2000, 2099);
o->precision(0);
Edit
Alternatively, create your own Hor_Value_Slider based on Fl_Hor_Value_Slider and override the draw method.
For the record: meanwhile FLTK 1.4.0 (not yet released) got new methods for sliders: value_width(int) and value_height(int), respectively. These methods let you set the width of the value field on horizontal and the height of the value field on vertical sliders.
Documentation can be found here:
https://www.fltk.org/doc-1.4/classFl__Value__Slider.html

How to get width of list control in MFC application in pixels?

I'm writing a dialog based MFC application on Visual Studio 2017 in C++.
I've added an option for the user to maximize\minimize the window. As the user resizes the dialog I want to adjust the sizes of the controls. In the app there's a list control as shown in the picture below, which adjusts to the new size of the window.
before maximizing the window - the width of each column is adjusted to the list width:
after maximizing the window:
My problem is that I'm having trouble to adjust it's columns to the new size. I've seen some posts on the subject, but unfortunately I still couldn't solve the problem. I want the columns to be about the same size and to fill the whole window.
what I've tried:
1. method 1 - the problem was that the last column was much bigger than the others
void CEditableListControlDlg::OnSize(UINT nType, int cx, int cy) {
if (m_bUseWMSize) {
// adjust column width to window
for (int i = 0; i < m_EditableList.GetHeaderCtrl()->GetItemCount(); ++i) {
m_EditableList.SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER);
}
}
m_bUseWMSize = true;
}
the variable m_bUseWMSize can be ignored - it's just a flag so I won't execute the code when the dialog is created. I've also tried switching the flage LVSCW_AUTOSIZE_USEHEADER inside SetColumnWidth to LVSCW_AUTOSIZE, but it didn't help either.
After using method 1 the list looks like this after maximizing the dialog:
2. method 2 - the problem was that the columns width wasn't affected. I think it's because the width variable has a value of 2147483647 and even if I divide it by 11 (the number of columns) it's still too big
void CEditableListControlDlg::OnSize(UINT nType, int cx, int cy) {
if (m_bUseWMSize) {
RECT rect;
m_EditableList.GetViewRect(&rect);
int width = abs(rect.left - rect.right);
int nCol = 11;
// adjust column width to window
for (int i = 0; i < m_EditableList.GetHeaderCtrl()->GetItemCount(); ++i) {
m_EditableList.SetColumnWidth(i, width/nCol);
}
}
m_bUseWMSize = true;
}
3. method 3 - I've tried to retrieve the width of the list in pixels and divide it by the number of columns. the problem was the the columns width was too small because the value of size.cx is 512
void CEditableListControlDlg::OnSize(UINT nType, int cx, int cy) {
if (m_bUseWMSize) {
CSize cz;
CSize size = m_EditableList.ApproximateViewRect(cz, -1);
int nCol = 11;
// adjust column width to window
for (int i = 0; i < m_EditableList.GetHeaderCtrl()->GetItemCount(); ++i) {
m_EditableList.SetColumnWidth(i, size.cx/11);
}
}
m_bUseWMSize = true;
}
relevant documentations:
SetColumnWidth Function
RECT struct
CSize struct
Functions ApproximateViewRect and GetViewRect
Thank you.
The easy option is to let the control do it for you :-). There is a special value you can pass (LVSCW_AUTOSIZE_USEHEADER) when sending an LVM_SETCOLUMNWIDTH message to the control, as per the following documentation topic:
https://learn.microsoft.com/en-us/windows/win32/controls/lvm-setcolumnwidth
Also referenced in that SetColumnWidth function link you mentioned in your post.
You could refer to the following code. Maybe it can help you.
bool CMFCApplication4Dlg::AdjustColumnWidth(CListCtrl* m_acclist)
{
CHeaderCtrl* pHeaderCtrl = m_acclist->GetHeaderCtrl();
int n = m_acclist->GetColumnWidth();
int nColumnCount = pHeaderCtrl->GetItemCount();
for (int i = 0; i < nColumnCount; i++)
{
m_acclist->SetColumnWidth(i, LVSCW_AUTOSIZE);
int nColumnWidth = m_acclist->GetColumnWidth(i);
m_acclist->SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER);
int nHeaderWidth = m_acclist->GetColumnWidth(i);
m_acclist->SetColumnWidth(i, nColumnWidth > nHeaderWidth ? nColumnWidth : nHeaderWidth);
}
return true;
}
Because LVSCW_AUTOSIZE_USEHEADER will resize last column to the remaining width, it won't help you since you want to evenly distribute total width across all columns.
Similar to your method 2 you could try the following:
For each column cycle through all rows including the header and use CListCtrl::GetStringWidth to get text width in pixels. Store the maximum width of each column
Sum up all these max widths
Get width of control client rectangle with GetClientRect. If scrollbar is present subtract it with ::GetSystemMetrics (SM_CXVSCROLL)
Subtract result of 2 from 3 and divide by number of columns. Add result to each of max widths obtained in 1
Use SetColumnWidth to assign new width for each column

Change bar color depending on value

I'm using chart-js/ng2-charts for an angular 2 app.
I can display a bar graph, but at the moment, all the bars are the same color. I'd like to have a different color depending on the value.
Can that be done?
After you create your chart, you can use the following function to loop through the dataset and change the color depending on the data value.
In this example, if the value is above a 50, the color changes to red.
var colorChangeValue = 50; //set this to whatever is the deciding color change value
var dataset = myChart.data.datasets[0];
for (var i = 0; i < dataset.data.length; i++) {
if (dataset.data[i] > colorChangeValue) {
dataset.backgroundColor[i] = chartColors.red;
}
}
myChart.update();
JSFiddle Demo: https://jsfiddle.net/6d0jsyxu/1/

Firemonkey: Shrink text font to fit in TLabel

I am attempting to lower the font size of a TLabel if its text is to large to fit in the confines of the label. I didn't see any properties I could set on the label to achieve this, so I have tried writing my own method. My method works by using TCanvas.TextWidth to measure the width of the text in a label, and shrink the font until the width of the text fits within the width of the label.
void __fastcall ShrinkFontToFitLabel( TCanvas * Canvas, TLabel * Label )
{
float NewFontSize = Label->Font->Size;
Canvas->Font->Family = Label->Font->Family;
Canvas->Font->Size = NewFontSize;
while( Canvas->TextWidth( Label->Text ) > Label->Width && NewFontSize > MinimumFontSize )
{
NewFontSize -= FontSizeDecrement;
Canvas->Font->Size = NewFontSize;
}
Label->Font->Size = NewFontSize;
}
This works some of the time, however other times it does not shrink the font near enough. It seems as if the value I get from calling Canvas->TextWidth is a lot of times, much smaller than the number of pixels wide the label actually needs to be in order to fit the text.
Am I using Canvas->TextWidth incorrectly? Is there a better way to calculate the width of a string, or to re-size the font of a TLabel so its text fits within its demensions?
Edit:
In this case, I am passing in to my function, the TCanvas that my label is sitting in. I have tried using that TCanvas as well as Label->Canvas. Both give me the same number for text width, and both are short of the actual value in pixels needed to display the whole string.
The following code is taken from code that works in an FMX application, modified slightly to remove arrays that are being iterated through and declaring a variable locally to the function. It is being run in a TForm method. Canvas here is the Form's Canvas. You can see that I'm using "- 35" at one point - this might be because the numbers weren't quite right.
double InitialFontSize = 30;
Canvas->Font->Size = InitialFontSize;
StoryHeadlineLabel->Font->Size = InitialFontSize;
bool fits = false;
do
{
double widthA = Canvas->TextWidth (StoryHeadlineLabel->Text);
if (widthA > StoryHeadlineLabel->Width - 35)
{
StoryHeadlineLabel->Font->Size --;
Canvas->Font->Size --;
}
else
fits = true;
if (StoryHeadlineLabel->Font->Size < 6)
fits = true;
} while (!fits);

Row Background Color GtkTreeView Widget

I'm attempting to color disabled rows in a gtk tree view widget a light gray color. From what I've read, I'm supposed to set the background-gdk property of the corresponding cellrenderer and bind it to a model column. This sort of works.
Gtk::CellRendererText* textRenderer = manage(new Gtk::CellRendererText());
textRenderer->property_editable() = false;
Gtk::TreeViewColumn *col = manage(new Gtk::TreeViewColumn("Column1", *textRenderer));
col->add_attribute(*textRenderer, "background-gdk", m_treeview_columns.m_back_color);
my_treeview.append_column(*col);
Gtk::TreeModel::Row row;
for (int i = 0; i < NUMBER_OF_ROWS; iLane++){
row = *(treeview_liststore->append());
row[m_workListColumns.m_back_color] = Gdk::Color("#CCCCCC");
}
In the end though, I get only the cells colored properly. BUT I also get an ugly white-space in between the cells. Does anyone know of a way to fix this or a better way to achieve the effect I'm after?
Could you set the background of the row to match the cell background or set the bakground of the tree view all together ? Or maybe the cell with cell-background-gdk ?