How to set excel cell as read-only using Laravel - Maatwebsite? - php

I want to download a report with sum of two columns to be displayed in another column. I want to make the answer cells to be read-only i.e., non-editable. How to make it using Laravel-Maatwebsite?
I have performed the sum formula.
$sheet->cell('C1', function($cell){
$cell->setValue("=SUM('A1:B1')");
});
I looked for protect cell function but I couldn't find.

I found one solution how you can use protected cell function
$sheet->protectCells('A1:F1', 'PASSWORD');
$sheet->getStyle('A2:F50')->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED);
// here in the place of F50 you can pass maximum range like F2000
$sheet->getDelegate()->getProtection()->setSheet(true);
Though the question was asked like 3 years ago but this might help someone in future !

Related

MySql: saving date ranges VS saving single day

I am currently working on a simple booking system and I need to select some ranges and save them to a mysql database.
The problem I am facing is deciding if it's better to save a range, or to save each day separately.
There will be around 500 properties, and each will have from 2 to 5 months booked.
So the client will insert his property and will chose some dates that will be unavailable. The same will happen when someone books a property.
I was thinking of having a separate table for unavailable dates only, so if a property is booked from 10 may to 20 may, instead of having one record (2016-06-10 => 2016-06-20) I will have 10 records, one for each booked day.
I think this is easier to work with when searching between dates, but I am not sure.
Will the performance be noticeable worse ?
Should I save the ranges or single days ?
Thank you
I would advise that all "events" go into one table and they all have a start and end datetime. Use of indexes on these fields is of course recommended.
The reasons are that when you are looking for bookings and available events - you are not selecting from two different tables (or joining them). And storing a full range is much better for the code as you can easily perform the checks within a SQL query and all php code to handle events works as standard for both. If you only store one event type differently to another you'll find loads of "if's" in your code and find it harder to write the SQL.
I run many booking systems at present and have made mistakes in this area before so I know this is good advice - and also a good question.
This is too much for a comment,So I will leave this as an answer
So the table's primary key would be the property_id and the Date of a particular month.
I don't recommend it.Because think of a scenario when u going to apply this logic to 5 or 10 years system,the performance will be worse.You will get approximately 30*12*1= 360 raws for 1 year.Implement a logic to calculate the duration of a booking and add it to table against the user.

Disabling auto-matching of two or more lines by their max values

I am using amchart (not stock chart) to generate charts of two or more datasets. I noticed that lines with different values are being adjusted by their max values. Please have a look at the attached screenshot:
As you can see for example the amount 1.8k is above the amount 4.2k because of the enabled auto-adjustment. Searching through the amcharts forum gave no result. Thanks you in advance!
UPDATE 1:
I have found one post with the similar problem, but I think it is quite not a good way
to adjust axises in such manner:
UPDATE 2:
Taking into consideration the #zerion's answer I have written some lines in my backend to be sure the synchronization will always be correct. I calculate min and max values for each numeral field that will be used as an axis, then using usort I sort the dataset array by (max - min) condition.
Yes, or you can even tell the axis to synchronize:
valueAxis2.synchronizeWithAxis(valueAxis1);
valueAxis2.synchronizationMultiplier = 1;
So you should only think of which of your axis has the widest range of values, and sync other axes to this one.
After more careful investigations I have found that the needed effect could be achieved by setting valueAxis.maximum (and maybe valueAxis.minimum if there are negative values) to the highest (lowest) value among all dataSets.

How to get the nearest places from a Latitude/Longitude in MySQL table? [duplicate]

This question already has answers here:
SQL query, select nearest places by a given coordinates [duplicate]
(4 answers)
Closed 9 years ago.
I want to make a table of with columns in a MySQL database:
Index
Latitude
Longitude
Places like place of Countries, Cities, People, Building etc.
With huge number of rows, in order of hundred thousands until million of rows.
If I want to get nearest places of a selected row in the table, how can I do that in the fastest way?
It is no problem if more information, indexing, or presorting are necessary.
======
Edit 1:
I have read the answer and the answer is using a formula, for example from the best answer:
(((acos(sin((".$latitude."*pi()/180)) * sin((geo_latitude*pi()/180))+cos((".latitude."*pi()/180)) * cos((geo_latitude*pi()/180)) * cos(((".$longitude."- geo_longitude)*pi()/180))))*180/pi())*60*1.1515*1.609344)
If I have 1 million rows, that means, there are 1 million of expensive calculation. I thing it will be very slow.
Are the optimization, for example using filtering in the beginning:
1. If the input is City A in location 10.000, 20.000, then filter cities that located at 9.000 to 11.00.
2. Calculate with the formula above.
How to optimize the speed of that algorithm?
====
Edit 2:
Sorry, I've only read the best answer.
I found what I've looked for in the other answer: http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
You can use a quadkey. A quadkey is a spatial index like a quadtree. It sort the points into a grid and then you can search the grid around the center point. It's not easy to understand but you can download my php class hilbert-curve # phpclasses.org. Or you can use the native MySQL spatial extension and the point datatype. However my implementation uses a quadkey and a hilbert-curve and can be better. It depends much on the data. The problem with the harvesine formula is that it is very slow. But you can use both algorithms together to achieve better results.

Mysql query to show results from between two columns

Hi i have a mysql database, in which i have two columns Year_from & Year_two.
what i am trying to do is find a way where i can show the dates that are missing as buttons, for example if year from is 2006 and year to is 2008, i of course want to show 2006, 2007 and 2008. is this possible, as there isn't the value of 2007 in the database.
I haven't worked on any code yet as i am not sure if this is possible, or how i would achieve it.
Any ideas would be appreciated.
Thanks
Use range($year_from, $year_to) to generate a list of all years. Compare that array with the one you got from the database using array_diff() and bold the missing ones.
This needs to be done in code.
Basically, you'll read a bunch of records from the database, iterate through an array of years you'd like to show and check (every iteration) if there is a matching record present in the result set.

Best way to search a comma separated mysql field

I have been given the task to combine 2 mysql fields into one and then make it so that the new field can be searched. The 2 fields I had to combine in my database where previous year registered and current years registered. The format both these fields are in are dd/mm/yyyy. I have combined these fields into a field called Years Registered whih is still in the same format dd/mm/yyyy but has the years registered seperated by a comma(,). I am wondering how I would go about performing a couple different kinds of querys on this column. The mysql queries I have to perform are: Show All() , Show All between dates: mm/yyyy and mm/yyyy , Before: mm/yyyy , After: mm/yyyy
Any help would be greatly appreciated.
Thanks for your time.
I don't like it but if you need you can use the next solution:
extract date using start_date = STR_TO_DATE(SUBSTRING(your_new_field, 1, 10))
and end_date=STR_TO_DATE(SUBSTRING(your_new_field, 12, 10))
Do not do this!
I do not know how it is exactly possible (some SQL Stringoperations and Datefunctions in a storedprocedurem i presume), but it will surely kill performance of your database.
use a relation for this.
This is:
way faster
more expandable (eg. for three dates..)
easier to code
much better understandable
more portable to other databases
If you have problems with existing platforms you have to support, use a code base where both alternatives are supported. This is still easier and better to maintain than to use a comma-separated list
Your database would be breaking 'First Normalized Form (1NF)' and would be highly ineffecient.
In order to search for a selected date, you would either have to query all rows in the table, or use LIKE which is also very sluggish.
Whoever is asking you to do this should read this article on database normalization.
What is wrong with using two DATE, or DATETIME fields and the formatting them outside of MySQL?

Categories