Create a column dropdown in EPPlus - epplus

I have everything else worked out but I want to put a drop down on a cell (range of cells) so that users are forced to select from the list.
I've tried this:
var dd = worksheet.Cells[5, 3, row, 3].DataValidation.AddListDataValidation() as ExcelDataValidationList;
dd.AllowBlank = true;
//Add list here
But I can't find any method or property that allows me to link the list.
How is this done? I can't find any documentation on it.

The correct way is to use the Formula.Values.Add:
dd = worksheet.Cells[5, 4, row, 4].DataValidation.AddListDataValidation() as ExcelDataValidationList;
dd.AllowBlank = true;
dd.Formula.Values.Add("Yes");
dd.Formula.Values.Add("No");

Related

Invalid parameter number when using whereNotIn in laravel

I want to print the list of option from database on my blade, which I want to get all list except the option that already selected. So what I've already do is getting the selected option (which is saved on another table) as an array:
$ctg_id[] = [];
foreach($vendor->category as $item){
$ctg_id[] = [$item->category_id];
}
Then finally print it:
$category = ItemCategory::whereNotIn('id',$ctg_id)->get();
But it return an error that says:
"SQLSTATE[HY093]: Invalid parameter number (SQL: select * from category_item where id not in (4, 3, ?))" Is there anything wrong with my code?
You are using double dimensional array, you need to change it to one dimensional:
$ctg_id = [];
foreach($vendor->category as $item){
$ctg_id[] = $item->category_id;
}
Recommend to use method-pluck like this:
$category = ItemCategory::whereNotIn('id', $vendor->category->pluck('category_id'))->get();

Google Sheets API (v4) - `AutoResizeDimensions` not working

I've got a system that generates and automatically maintains lots of spreadsheets on a Drive account.
Whenever I add data to the sheet I run a 'format' method to pass over and make sure everything is ok.
This generally does things like:
set the default font and size across the sheet
set up the heading row
freeze rows
In addition, I have the code below to make sure the first two columns (index 0 and 1) in the sheet are autoresizing to fit their contents. when I run it though, this element doesn't seem to make a difference. The font, column freezes etc all work.
Other notes:
I only want those 2 columns to auto-resize
the amount of rows in a sheet can vary
this job is appended to the end of several in requestList
My code:
requestList.Requests.Add(new Google.Apis.Sheets.v4.Data.Request()
{
AutoResizeDimensions = new AutoResizeDimensionsRequest()
{
Dimensions = new DimensionRange()
{
SheetId = Convert.ToInt32(sheetId),
Dimension = "COLUMNS",
StartIndex = 0,
EndIndex = 1
}
}
});
var updateRequest = sheetService.Spreadsheets.BatchUpdate(requestList, spreadSheetId);
var updateResponse = updateRequest.Execute();
Could the order which I request the 'format' changes be affecting things maybe? Can anyone help?
As written in the documentation,
the start index is inclusive and the end index is exclusive.
So, For the first two columns, it should be
startIndex = 0,
endIndex = 2

How to get first row from Google Spreadsheets Data API

Here is an example: https://spreadsheets.google.com/feeds/list/1a2JzZzUjSIcpROgR5v_M-UmWyT-iokcegIxHJOopZWA/od6/public/full?alt=json
The returned JSON data doesn't contain the first row from the spreadsheet.
You can view the contents of the spreadsheet in HTML (https://docs.google.com/spreadsheets/d/1a2JzZzUjSIcpROgR5v_M-UmWyT-iokcegIxHJOopZWA/pubhtml) to verify that "first row" exists in the sheet.
How can I get the first row from the spreadsheet? There is a "openSearch$startIndex" = 1 in the returned JSON. Maybe if you could set this to 0, I could get the first row also.
1st Row - Cell feed
https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full?min-row=1&min-col=1&max-col=4
Docs: https://developers.google.com/google-apps/spreadsheets/#fetching_specific_rows_or_columns
Cell feed is better for almost everything. But append a data row is better in list feed, I think.
In C# you would do it like this:
var link = worksheet.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null).HRef.ToString();
var cellQuery = new CellQuery(link)
{
MinimumRow = 1,
MaximumRow = 1,
MinimumColumn = 1
};
CellFeed header = spreadsheetService.Query(cellQuery);

Apache POI - DROP DOWN value removing '00000' from data

I am building dynamic drop down through java code and it is working perfectly fine.
The code I am running is:
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Data Validation");
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
dvHelper.createExplicitListConstraint(new String[]{"0000011", "0000021", "0000031"});
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(
dvConstraint, addressList);
validation.setShowErrorBox(true);
validation.setSuppressDropDownArrow(true);
sheet.addValidationData(validation);
Drop down are coming properly but when I select any one of the value from drop-down 00000 are automatically removed and only 11 is getting displayed, but I want value to be 0000011 to be selected from drop down.
drop value is showing as 0000011 but after selection it display 11. Might be if we can change cell type to text it will help or some other way but how to do it?
I solved this on my own after lot of research. so I thought to post answer to help others.
// setting cell type as string to avoid removing 00000 from drop down
CellStyle textStyle = workbook.createCellStyle();
textStyle.setDataFormat((short)BuiltinFormats.getBuiltinFormat("text"));
sheet.setDefaultColumnStyle(0, textStyle);

Disable or enable edit for selective cell in dojox data grid

How to disable or enable edit for selective cell in dojox data grid i.e
Imagine I have two columns (A, B) in a data grid. I want column value of B to be editable based on the value of column A. I have seen one solution in stack overflow which was specific to a DOJO version. I would like to know if there are APIs by which we can achieve above objective.
My preferred method is to override the
canEdit: function(inCell, inRowIndex)
method of the DataGrid. From that, you can get the item:
this.getItem(inRowIndex)
then work out if it should be editable or not, and return true/false.
This does override the editable flag on the column though, so you'll need to do something with that if needed.
There is no API as such. I also had similar requirement recently and here is how I implemented it:
1) Initially the column B is editable because I made it so in the Fields section of grid
2) Use onRowClick to capture the rendering of rows. Something like this should do
dojo.connect(grid, "onRowClick", grid, function(evt){
var idx = evt.rowIndex,
item = this.getItem(idx);
// get a value out of the item
msname = this.store.getValue(item, "msname");
if(msname != null &U& (trim(msname) == trim(offsetName))) {
dojox.grid.cells._Base.prototype.format(idx, item);
}
});
The following method then disallows inline editing of required column. We are passing row index and column index to this following function:
dojox.grid.cells._Base.prototype.format = function(inRowIndex, inItem){
var f, i=grid.edit.info, d=this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
d = (d && d.replace && grid.escapeHTMLInData) ? d.replace(/&/g, '&').replace(/</g, '<') : d;
//Check inRowIndex and inItem to determine whether to be editable for this row here.
if(this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndex && i.cell==this))){
return this.formatEditing(d, inRowIndex);
}else{
return this._defaultFormat(d, [d, inRowIndex, this]);
}
}
Hope that helps. Probably you can add a jsfiddle and we can try fixing it.