I can't find a way to append multiple values to multiple rows, like I do with .update method with the same range value.
service.spreadsheets().values()
.append(
spreadsheetId,
"sheet!A2:B300",
new ValueRange().setValues(Arrays.asList(Arrays.asList("1", "2")))
)
.setValueInputOption("USER_ENTERED").execute();
The message I get is:
"Requested writing within range [sheet!A2], but tried writing to column [B]"
If I use all the same arguments with the .update method instead of .append, everything works nicely.
Also, .append will work if the inner list has only 1 item
-
Thanks
EDIT: I was using HH:mm string as a part of sheet name. It was causing the range error. The same worked on .update method so I didn't consider it important at first
Remove the colon from the name of your worksheet, and this apparent bug in the append feature of the Spreadsheet API will go away.
Append works by finding a table within the requested range and then appending data to the end of that table. The table it found appears to only have one column (in 'A'), and append is having trouble adding the new column. You can resolve this by adding a column header in B, most likely.
Admittedly, this isn't super intuitive, so we'll take a look at changing the behavior.
Related
I have a varchar column. It contains values separated by semicolon (;).
For example, it looks like
10;20;21;17;20;21;22;
It's not always 7 elements. It could contain anything from around 30 to 70. The reason they designed it this way is because the values are actually genome segments and it makes sense to enter or retrieve it collectively
I need to remove records with duplicate columns, so if I see another record with the same value as above, I need to remove it.
I also need to remove the record if it contains same values in another record. For example, I need to remove
10;;21;17;20;21;22;
because it's the same as the first but it doesn't have the second value, 20. If it's more complete than the first, I will remove the first one instead.
1;2;3;4;5;6;7; and 1;2;3;4;5;6;7;8; are dups and I'm taking the 2nd one because it's more complete. 1;2;3;4;5;6;;7 is also a duplicate. In this case, if they have 13 or more matched numbers and no mismatch, we will merge them so it becomes a single value 1;2;3;4;5;6;7;7;.
I can scan each record in java but I'm afraid that it will be complicated and time consuming, given that the table contains millions of records. I was wondering if it's doable in oracle itself.
My final goal is to calculate the frequency that those numbers occur. For instance, if number 10 appears 5 out of 100 times, it will be 5%. The calculation will be simple. However, I can't calculate this unless I make sure there's no duplicates in the table in the first place.
Note: This answer is a placeholder because the question looks in danger of closure but I think it will be worthy of an answer once all the rules are established.
It's trivial to remove the exact duplicates:
delete from your_table y
where y.rowid not in ( select min(x.rowid)
from your_table x
group by x.genome_string)
The hard part is establishing duplicating strings which have exact matches and nulls. Merging rows makes the logic even more convoluted.
The sql below is a solution ONLY IF:
1;2;3;4;5; is a more complete form of 1;2;;5
All your entries end with ;
The request was tested using sqlite so perhaps it may need some changes for Oracle.
It expects a table "TEST" with a column "VALUE"
SELECT
DISTINCT VALUE
from TEST As ORIGIN_TEST
WHERE NOT EXISTS (SELECT VALUE FROM TEST
WHERE
VALUE <> ORIGIN_TEST.VALUE AND
(VALUE LIKE replace(ORIGIN_TEST.VALUE, ';;', ';_%;') OR
VALUE LIKE ORIGIN_TEST.VALUE || '_%;')
)
I was using glpsol with a .mod file containing both the problem and the data for it.
However, I want to use its Java API to instantiate the problem within my application, without the need to write/read files and run them with glpsol.
In my problem, I have "sets" that are given afterwards in the data section, and also params in function of these sets, for example:
set ROBOTS;
param L{ROBOTS}, integer;
And then, at the data section:
data;
set ROBOTS := ag1 ag2 ag3;
What I want to know is what method can I use to add such params to the problem, as well as how to retrieve them.
In order to observe how this problem was being represented, I've tried reading the problem and the data from files and extracted the rows and cols of the problem through the methods glp_get_row_name and glp_get_col_name. I came to the conclusion that the rows are the objective and constraints, whilst the columns are the values of a var f that is declared as follows and used in some of the constraints as well as in the objective:
var f{ROBOTS,SUBTASKS}, binary;
I could not find in the documentation a way to extract these params from the problem. Also, I have no idea about where my other vars went, since only f appeared in the columns. But as the program was able to solve the instantiated problem and had the same result as the solution given by glpsol, I know that it has all of this data, I just want to know where it stores it.
I was reading the documentation from here: http://glpk-java.sourceforge.net/apidocs/org/gnu/glpk/GLPK.html
Sorry for the lack of correct terminology. Thanks in advance.
var f{ROBOTS,SUBTASKS}, binary;
ROBOTS and SUBTASKS only exist in the GMPL language model.
After the model is translated the problem is stored as a sparse matrix. You only have column numbers and row numbers for addressing.
I would like to create some rows in a spreadsheet using Apache Poi. To do so I have to format the number to meet some specifications
So my initial number is a double (in a String ><) like this one
String initial = "1234.56";
and I would like to store it in this format
String wanted = "1 234";
So I use this code to parse it (and it works fine)
wanted = NumberFormat.getNumberInstance(Locale.FRANCE).format(Double.valueOf(initial).intValue())
But when I create the spreadsheet, and open it (with excel), I get this error ONLY a few values
number stored as text
I tried to solve it using
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
but it did not work.
The strange thing is that this error is not on all the values (all values come from the same function). See this screenshot for example
Did I do something wrong ? Did I miss something ? Does someone have an idea to solve it ?
Problem solved using
HSSFCellStyle style = workbook.createCellStyle();
style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0"));
and
int value = Double.valueOf(initial).intValue();
cell.setCellValue(value);
I already tried using this DataFormat, but in order to work, you need to insert a number, not a String.
cell.setCellValue("12345"); //Will be inserted as 12345. Echec !
cell.setCellValue(Integer.valueOf("12345")); //Will be inserted as 12 345. Success ;)
I am trying to update the records in database according to data read from an Excel sheet. I have more than 50 columns in db whose column names are stored in an array columnNames[].
I use following code to create the Sql query.
String sqlUpdate= "Update "+tableName+
" set "+columnNames[0]+"=?";
for (int i=1;i<columnCount;i++)
{
sqlUpdate= sqlUpdate+","+columnNames[i]+"=?";
}
sqlUpdate= sqlUpdate+
" where demand_id=?";
the equivalent query obtained to printing it on console is :
Update fulfillment_plan set DEMAND_ID=?,SBU=?,PROJ_DOMAIN=?,JOBCODE=?,INDENT_STATUS=?,JC_CREATED_ON=?,PROJECT_NAME=?,CUSTOMER_NAME=?,GROUP_CUSTOMER=?,US_DEMANDS=?,SUITE_NAME=?,ROLE_NAME=?,LOCATION=?,COUNTRY=?,GEO=?,AREA=?,OPEN_POS=?,PRODUCT=?,DEMAND_TYPE=?,POSITIONS_TO_FULFILL_Q4=?,FULFILLMENT_PLAN_Q4=?,TA_STATUS_Q4=?,POSITIONS_TO_FULFILL_Q3=?,FULFILLMENT_PLAN_Q3=?,TA_STATUS_Q3=?,POSITIONS_TO_FULFILL_Q2=?,FULFILLMENT_PLAN_Q2=?,TA_STATUS_Q2=?,POSITIONS_TO_FULFILL_Q1=?,FULFILLMENT_PLAN_Q1=?,TA_STATUS_Q1=?,NET_ADD_TYPE=?,ESSENTIAL_SKILL=?,SUITE_SKILLS=?,ADDITIONAL_SKILLS=?,POSITIONS_WITH_PROPOSALS=?,POSITIONS_WITHOUT_PROPOSALS=?,DEM_ST_DATE=?,OVER_DUE_STATUS=?,OVERDUE_DAYS=?,LEAD_TIME_DAYS=?,LEAD TIME BUCKET=?,DEM_END_DATE=?,CREATED_ON=?,INDENT_CREATED_ON=?,EBD=?,OPPORTUNITYID=?,LOAD_DATE=?,PROJECT_NUMBER=?,CUSTOMER_NO=?,CUSTOMER_SUB_GEO=?,DEMAND_STATUS=?,ENGAGEMENT_TYPE=?,INVOICE_TYPE=?,INDENT_CLASSIFICATIONS=?,PROJ_STAT=?,EFD_SLA=?,RM_EMP_NAME=?,MONTH=?,QUARTER=?,YEAR=?,ACCOUNT_ID=?,ACCOUNT_TEXT=?,STATUS=? where demand_id=?
Then i have set the values to the '?' and on executing the above prepared statement in am getting the "missing equal sign" error. I have been looking into it for around 3 hours now and am not able to solve it. Kindly help.
I suspect this is due to the LEAD TIME BUCKET column name, which should either have underscores (like the other column names) or be escaped somehow - the spaces within the column name are causing the error. It would be better to have underscores in order to be consistent with your other columns, and to make the SQL simpler.
(I'd also suggest adding spaces within your SQL - e.g. one after every comma - so that the SQL can be reformatted in a text editor by line-breaking on spaces, making it easier to read. I'd have more whitespace in the Java code too, but that's clearly a matter of personal/team preference.)
I'm converting (or trying to) an Ms AccessDB into derby.
When I extract the data from certain varchar / text / memo field from access they are filled with apostrophe, and mathematical symbols (percent, less than etc), and possible foreign characters
I need to keep these and I test for them so as I can use an 'escape sequence' to ensure they get put into the database.
However for now I am unable to get the data into the DB without it failing on these fields. When the SQL fails I output the SQL string, and cut and past it into ij. Then I modify just the first record, and it is always these characters that cause me grief.
I've tried to modify the strings by surrounding with "double quote marks" but that just gives a different error (stating that it has 'enounterd """ at line1 column x' which is always the first occurance of the double quote).
I haven't found a setting in derby to alter the behaviour for strings, yet. Is there one?
I have also tried to set the SQL statment to a preparedStatement then use the {call preparedStatement} again this fails also. I can't use the {escape "escape char} in a normal statment as derby just says incorrect syntax at me.
How do others manage to get user content with strange characters into a field in derby?
Do I need to change my field into a CLOB or something other than varchar / long Varchar?
Are my problems being caused by using the wrong characteset (eg iso rather UTF-8), how do I tell what it is, how to change it?
Below is a sample of the SQL insert that fails when I send it to derby (via my JAVA 'programme')
insert into S1.SORTIEDESSAI (OBS, DATEDUSORTIE, CONTREINDIC, FIN,
PDEVU, REFUS, INVDECISN, ADMIN, MOTIF_DE_LA_SORTIE, NOMVALIDEE,
DATEVALIDEE) values ('"0001/0001"' , '2007-07-15' , false , true ,
'"null"' , '"null"' , '"null"' , '"null"' , '"2. FIN DE L’ESSAI"' ,
'"DR SIMON"' , '2011-04-19' )
Note:
Actually I look at the above and notice that the order of columns names isn't good? It was OK yesterday, not sure why it would have changed? something to do with Access returning the column names in a random order from the resultSetMetaData, which would be a surprise.
for now I recomend any further answers to hold off whilst I sort this problem out, OK solved that problem, do I need to set another question about this behaviour....
Back to the main thread...
Ok as you can see on my SQL statement I have wrapped any varchar fields in double quotes. This always fails (even directly through ij). help help help...
I'm not quite sure what your question is, but in general you can input these characters by using a PreparedStatement of the form: INSERT INTO tablename (columnname) values (?), and then using the PreparedStatement.setString() method to supply your character data for that column.