Why does this code not set the background color for a cell (Aspose Cells)? - aspose

I need a cell to have a light blue background color; I have code that works in another sheet, but the same exact code (except for the names of the vars and column index val):
Style styleShipVariance = null;
CellsFactory cfShipVariance = new CellsFactory();
Cell ShipVarianceCell = customerWorksheet.Cells[0, SHIPVARIANCE_COL];
ShipVarianceCell.PutValue("Ship Variance");
styleShipVariance = cfShipVariance.CreateStyle();
styleShipVariance.HorizontalAlignment = TextAlignmentType.Left;
styleShipVariance.Font.Name = fontForSheets;
styleShipVariance.Font.IsBold = true;
styleShipVariance.Font.Size = 11;
styleShipVariance.ForegroundColor = Color.LightBlue;
styleShipVariance.Pattern = BackgroundType.Solid;
ShipVarianceCell.SetStyle(styleShipVariance);
...does not work on the other sheet. The value ("Ship Variance") is displayed in that cell, but the color is not being applied.
Why would this not work? What is missing?
Note: I also tried adding this:
var flag = new StyleFlag
{
CellShading = true,
FontName = true,
FontSize = true,
FontColor = true,
FontBold = true,
NumberFormat = true
};
...and changing the last line above to:
ShipVarianceCell.SetStyle(styleShipVariance, flag);
...but it made no difference.
UPDATE
I am saving as xlsx:
var filename = String.Format(#"{0}\{1} - Fill Rate - {2}.xlsx", sharedFolder, _unit, fromAsYYYYMMDD);
if (File.Exists(filename))
{
File.Delete(filename);
}
workBook.Save(filename, SaveFormat.Xlsx);
UPDATE 2
I just noticed that the vals are also not being bolded or left-aligned. The text values themselves are being assigned, but none of the formatting is...
UPDATE 3
Why it was necessary, I don't know, but by adding the colorizing code AFTER the data rows were added to the sheet, it works now.

Well, normally it should work fine. But if you are saving to an XLS file (instead of XLSX file), the light blue background color might not be applied so, you got to add to MS Excel color palette first via the line of code:
e.g
Sample code:
.........
workbook.ChangePalette(Color.LightBlue, 55);
Anyways, we need your template Excel file, so we could evaluate your issue precisely and test to apply the color to the cell on our side and guide you appropriately. I think you may follow up your thread in the Aspose.Cells forums.
I am working as Support developer/ Evangelist at Aspose.

Related

Simple relative cell referencing in google code

I have made this virtual inventory with buttons that copy and paste values to various sheets for different types of reports. The code might not be optimal I am not much of a programmer but I'm trying my best. now I have the same button in multiple places and I want it to copy values in cells relative to the position of the button itself but I am not sure how to reference a cell in a relative manner in the getRange fucntion.
here is the code:
function Go() {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var sheet = SpreadsheetApp.getActiveSheet();
var destSheet = ss.getSheetByName("Fiche");
var lastRow = destSheet.getLastRow();
var source = ss.getRange ('(rowid-3)(colid)');
var checkbox = sheet.getRange (3,3);
var destColumn = ss.getRange ('B10').getValues ();
source.copyTo(destSheet.getRange(lastRow + 1,1), {contentsOnly: true});
if (checkbox.getValue() == 'vrai' ) {
var source = ss.getRange ('B9');
source.copyTo(destSheet.getRange(lastRow + 1, destColumn), {contentsOnly: true});
source.copyTo(destSheet.getRange(lastRow + 1, 2), {contentsOnly: true});
}
else {
var nombre = ss.getRange ('D5').getValues() ;
destSheet.getRange(lastRow + 1, destColumn).setValue(nombre);
destSheet.getRange(lastRow + 1, 2).setValue(nombre)
}
I want all (B10),(B9), etc. format cells to be replaced with relative cell positons. I have tried with (colID)(rowID) but it doesn't seem to work
I believe your goal as follows.
You want to retrieve the cell coordinate when a button on Spreadsheet is clicked.
Modification points:
Unfortunately, in the current stage, when a button on Spreadsheet is clicked, there are no methods for directly retrieving the information where button is clicked.
So when you want to use the button on Spreadsheet, if you want to retrieve the information, it is required to prepare each script for each button. But I thought that this might be different from the direction you expect.
In this answer, in order to retrieve the information where the button is clicked, I would like to propose the following 2 patterns as the workarounds. In these patterns, the event object is used. By this, the information of the button can be retrieved. This is used.
Pattern 1:
In this pattern, a cell is used as the button using the simple trigger of OnSelectionChange. When the cell "B3" is used as the button like above image, the script is as follows.
Sample script:
In this script, for example, when you want to use the cell "B3" of "Sheet1" as the button, please set "B3" to buttonRanges. And, set sheet.getSheetName() != "Sheet1". When when you want to use the cell "B3" and "B4" as the button, please set "B3" and "B4" to buttonRanges.
function onSelectionChange(e) {
const range = e.range;
const sheet = range.getSheet();
const buttonRanges = ["B3"];
if (sheet.getSheetName() != "Sheet1" || !buttonRanges.includes(range.getA1Notation())) return;
const row = range.getRow(); // This is the row number.
const column = range.getColumn(); // This is the column number.
}
In this case, when the cell "B3" is clicked, this script is run. And row and column are the row and column number of the cell.
Because the cell is used as the button, you can put the value to the cell.
Pattern 2:
In this pattern, a checkbox is used as the button using the OnEdit trigger. When the cell "B3" is used as the button like above image, the script is as follows.
Sample script:
In this script, for example, when you want to use the cell "B3" of "Sheet1" as the button, please set "B3" to buttonRanges. And, set sheet.getSheetName() != "Sheet1". When when you want to use the cell "B3" and "B4" as the button, please set "B3" and "B4" to buttonRanges.
function onEdit(e) {
const range = e.range;
const sheet = range.getSheet();
const buttonRanges = ["B3"];
if (sheet.getSheetName() != "Sheet1" || !buttonRanges.includes(range.getA1Notation()) || !range.isChecked()) return;
const row = range.getRow(); // This is the row number.
const column = range.getColumn(); // This is the column number.
}
In this case, when the checkbox is checked, the script is run. When the checkbox is unchecked, the script is not run.
Because the checkbox is used as the button, you cannot see the text in the cell.
References:
Simple Triggers
Event Objects
Related question
Button change text display every after click
This question is for achieving the switching button.

c++ builder Excel Ole Create new worksheet after the last sheet

I want to add a new worksheet not at the beginning but at the end of the worksheet tabs. But i can only manage to get it working at the front.
workSheet = workSheets.OleFunction("Add");
How can i change this line of code to make it add at the end ?
The Worksheets.Add() method has optional Before and After parameters:
Before
An object that specifies the sheet before which the new sheet is added.
After
An object that specifies the sheet after which the new sheet is added.
...
If Before and After are both omitted, the new sheet is inserted before the active sheet.
You need to set After param
Excel::_WorksheetPtr newSheet;
if (const auto sheetsCount = m_book->Worksheets->GetCount(); sheetsCount == 0)
newSheet = m_app->Worksheets->Add();
else
{
IDispatchPtr dispatch = m_app->Worksheets->GetItem(sheetsCount); // Number of sheet, not index
newSheet = m_app->Worksheets->Add(vtMissing, dispatch.GetInterfacePtr(), 1);
}
return newSheet;

MFC: Highlight a line in CRichEditCtrl for some duration and revert back

I am pretty new to MFC,C++ programming, Please help me in this issue.
In an edit box (created with CRichEditCtrl) there are several lines. I need to highlight one line(with red color) for some duration (example: highlight line 1 for 1 second and after that revert back the line color).
How can I do that?
Thanks in advance
First set your settings like this
`
// Select your string (start is the index in characters (not in lines)
GetRichEditCtrl().SetSel( nStart, nStart + nLength);
// Get the CHARFORMAT structure ready
CHARFORMAT cf;
cf.cbSize = sizeof (cf);
cf.dwEffects = 0;
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
GetRichEditCtrl().SetSelectionCharFormat(cf);
`
Then create a timer like with SetTimer(WMT_MYTIMER,1000,NULL), override OnTimer, stop the timer with KillTimer and reset the color as above
Hope this helps!

Raphael bar chart - bc.bars.length always returning 1

Hi I am using Raphael to generate a bar chart on my web and would like to attach an index to the bars following the replies in this page
https://stackoverflow.com/questions/4057035/raphaeljs-charts-bar-index-fetching?answertab=votes#tab-top.
In order to do this, I will need to fetch the value of bc.bars.length. However, no matter how many bars are in my bar chart, bc.bars.length always returning 1.
Here is my code:
//Create a bar chart using the values in the selected objects
r = Raphael("bar");
txtattr = { font: "12px arial" };
r.text(160, 10, "Title").attr(txtattr);
var bc = r.barchart(10, 10, 300, 220, [myData]).hover(fin, fout);
alert(bc.bars.length); //always returning 1
Anyone knows what is going wrong here? Thanks in advance.
this might be a little late, but for anyone out there, you know, I found myself in the same situation, so let me share my answer and the things I noticed:
(I'm using graphael 0.5.1)
-I noticed that when you use and array for the bars, it returns 1, like what you have:
var bc = r.barchart(10, 10, 300, 220, [myData])
alert(bc.bars.length); //always returning 1
-BUT if you put the values directly, like:
var bc = r.barchart(10, 10, 300, 220, [100,450,340,500])
alert(bc.bars.length); //seems to return 4
-BUT ! that doesn't work if you are getting dinamic data!
so THE SOLUTION I'VE FOUND IS THIS:
//after creating the barchart, let's loop it
var i = 1;
bc.each(function() {
i++;
console.log("bar: "+ i);
});
var total_bars=i-1;
console.log('total_bars: '+total_bars)
I hope this helps other people =), this is a nice library to chart, but it's a shame it's a little buggy with each new version, like the labels and such =(

How do I add a ComboBox to a TreeView column?

In Gtkmm, I want to have a Gtk TreeView with a ListStore, and have one of the columns in the list be a ComboBoxText. But I can't seem to figure out how to do it.
What I currently have looks like:
class PlayerListColumns : public Gtk::TreeModelColumnRecord
{
public:
PlayerListColumns()
{ add(name); add(team);}
TreeModelColumn<string> name;
TreeModelColumn<ComboBoxText*> team;
}
Then when setting the TreeView (the player_list_view object)
PlayerListColumns *columns = new PlayerListColumns();
Glib::RefPtr<ListStore> refListStore = ListStore::create(*columns);
player_list_view->set_model(refListStore);
ComboBoxText *box = manage(new ComboBoxText());
box->append("Blah");
box->append("Blah");
box->append("Blah");
TreeModel::Row row = *(refListStore->append());
row[columns->name] = "My Name";
row[columns->team] = box;
The column "name" shows up just fine, but no ComboBox. I'm almost positive that simply having a pointer to a combo box as the column type is wrong, but i don't know how it's supposed to go. I do get GTK warning:
GLib-GObject-WARNING **: unable to set property text' of typegchararray' from value of type `GtkComboBoxText'
Which seems to indicate (from a small bit of Googling) that there isn't a default renderer for non-basic types. But I haven't been able to find any examples of how to set one up, if that were the problem. All the tutorials only show TreeViews with primitive data types.
Anyone know how to put a ComboBox into a TreeView?
Okay, I haven't gotten it working 100%, but this example class should get you on the right track:
http://svn.gnome.org/svn/gtkmm-documentation/trunk/examples/book/treeview/combo_renderer/
Basically you need to add a Gtk::TreeModelColumn<Glib::RefPtr<Gtk::ListStore> > to your columns class and a Gtk::TreeModelColumn<string> to hold the selected data.
Then, to make a column a combobox, you have to add:
//manually created column for the tree view
Gtk::TreeViewColumn* pCol = Gtk::manage(new Gtk::TreeViewColumn("Choose"));
//the combobox cell renderer
Gtk::CellRendererCombo* comboCell = Gtk::manage(new Gtk::CellRendererCombo);
//pack the cell renderer into the column
pCol->pack_start(*comboCell);
//append the column to the tree view
treeView->append_column(*pCol);
//this sets the properties of the combobox and cell
//my gtkmm seems to be set for Glibmm properties
#ifdef GLIBMM_PROPERTIES_ENABLED
pCol->add_attribute(comboCell->property_text(), columns->team);
//this is needed because you can't use the ComboBoxText shortcut
// you have to create a liststore and fill it with your strings separately
// from your main model
pCol->add_attribute(comboCell->property_model(), columns->teams);
comboCell->property_text_column() = 0;
comboCell->property_editable() = true;
#else
pCol->add_attribute(*comboCell, "text", columns->team);
pCol->add_attribute(*comboCell, "model", columns->teams);
comboCell->set_property(text_column:, 0);
comboCell->set_property("editable", true);
#endif
//connect a signal so you can set the selected option back into the model
//you can just have a column that is not added to the view if you want
comboCell->signal_edited()
.connect(sigc::mem_fun(*this,&ComboWindow::on_combo_choice_changed));
EDIT ABOVE
I think something along the lines of using a Gtk::CellRendererCombo* is the way to go in your PlayerListColumns
http://developer.gnome.org/gtkmm/stable/classGtk_1_1CellRendererCombo.html
(I haven't made a working test yet, but I got the idea from:
http://developer.gnome.org/gtkmm-tutorial/unstable/sec-treeview.html.en#treeview-cellrenderer-details)