I'm able to update a single NamedRange using Update(), and multiple GridCoordinate ranges using BatchUpdate, but I can't work out how to update NamedRanges in a BatchUpdate. How is this done?
The single NamedRange update I can do like this:
ValueRange vr = new ValueRange();
vr.Range = "aRange";
var l1 = new List<object>();
l1.Add("Here");
IList<IList<object>> l2 = new List<IList<object>>();
l2.Add(l1);
vr.Values = l2;
var rqe2 = service.Spreadsheets.Values.Update(vr, spreadsheetId, "aRange");
rqe2.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
rqe2.Execute();
and a GridCoordinate via BatchUpdate I can do like this:
BatchUpdateSpreadsheetRequest busr = new BatchUpdateSpreadsheetRequest();
busr.Requests = new List<Request>();
Request r = new Request();
busr.Requests.Add(r);
r.UpdateCells = new UpdateCellsRequest();
var gc = new GridCoordinate();
gc.ColumnIndex = 0;
gc.RowIndex = 5;
gc.SheetId = 0;
r.UpdateCells.Start = gc;
r.UpdateCells.Fields = "*";
r.UpdateCells.Rows = new List<RowData>();
var rd = new RowData();
r.UpdateCells.Rows.Add(rd);
rd.Values = new List<CellData>();
var cd = new CellData();
cd.UserEnteredValue = new ExtendedValue();
cd.UserEnteredValue.StringValue = "UserEnteredValue";
rd.Values.Add(cd);
SpreadsheetsResource.BatchUpdateRequest bur = service.Spreadsheets.BatchUpdate(busr, spreadsheetId);
bur.Execute();
You're using two different kinds of updates above, values.update & spreadsheets.batchUpdate.
The values API collection works with A1 ranges, which include named ranges, sheet names, row numbers (1-based) and column letters. The spreadsheets API collection works with GridRange, GridCoordinate, DimensionRange, etc.. objects, all of which work with sheet IDs and row/column indexes (0-based).
If you'd like to do a batch update of values within named ranges, you want to use the values.batchUpdate API, not the spreadsheets.batchUpdate API.
The API in C# should be a fairly straightforward mapping of the info on the reference docs, probably using SpreadsheetsResource.ValuesResource.BatchUpdateRequest.
Related
I have to copy existing sheet and rename it. And I cannot find any info how to rename the sheet via Google sheets API v4.
For now I have:
var defaultSheet = service.Spreadsheets
.Get(spreadsheetKey)
.Execute().Sheets
.First(x => x.Properties.Title.Equals("Default sheet"));
var newSheet = Service.Spreadsheets.Sheets.CopyTo(
new CopySheetToAnotherSpreadsheetRequest { DestinationSpreadsheetId = spreadsheetKey },
spreadsheetKey,
(int)defaultSheet.Properties.SheetId);
I hope anyone has any idea how to do it.
Thanks in advance!
Solution (how to copy sheet with specified name):
var defSheet = Service.Spreadsheets.Get(baseUrl).Execute().Sheets.First(x => x.Properties.Title.Equals("OldSheet"));
var newSheet = new Request
{
DuplicateSheet = new DuplicateSheetRequest
{
SourceSheetId = defSheet.Properties.SheetId,
NewSheetName = "NewSheet",
InsertSheetIndex = 1
}
};
var y = new BatchUpdateSpreadsheetRequest { Requests = new List<Request> { newSheet } };
Service.Spreadsheets.BatchUpdate(y, baseUrl).Execute();
Below is the code I'm working with to pass multiple line items to create sales order through GP Web service. I can pass single Line Item without any problem , but when I pass multiple Items it is only taking the last one. The array has around 5 Item ID and I'm passing fixed Quantity as 15, Need to make both dynamic. But for the testing purpose I'm trying like this. I know the problem with the creation/initialization of some web service objects. As novice to the entire set of things I couldn't find the exact problem.
C# Code
CompanyKey companyKey;
Context context;
SalesOrder salesOrder;
SalesDocumentTypeKey salesOrderType;
CustomerKey customerKey;
BatchKey batchKey;
// SalesOrderLine salesOrderLine;
ItemKey orderedItem;
Quantity orderedAmount;
Policy salesOrderCreatePolicy;
DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.UserName = "Admin";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Password = "pass";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Domain = "Gp";
System.ServiceModel.WSHttpBinding binding;
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);
context = new Context();
companyKey = new CompanyKey();
companyKey.Id = (1);
context.OrganizationKey = (OrganizationKey)companyKey;
salesOrder = new SalesOrder();
salesOrderType = new SalesDocumentTypeKey();
salesOrderType.Type = SalesDocumentType.Order;
salesOrder.DocumentTypeKey = salesOrderType;
customerKey = new CustomerKey();
customerKey.Id = "121001";
salesOrder.CustomerKey = customerKey;
batchKey = new BatchKey();
batchKey.Id = "RMS";
salesOrder.BatchKey = batchKey;
// SalesOrderLine[] orders = new SalesOrderLine[6];
SalesOrderLine[] lines = { };
for (int i = 1; i < 5; i++)
{
SalesOrderLine salesOrderLine = new SalesOrderLine();
orderedItem = new ItemKey();
orderedItem.Id = Arr[i].ToString();
salesOrderLine.ItemKey = orderedItem;
orderedAmount = new Quantity();
orderedAmount.Value = 15;
salesOrderLine.Quantity = orderedAmount;
lines = new SalesOrderLine[] { salesOrderLine };
MessageBox.Show(lines.Count().ToString());
}
salesOrder.Lines = lines;
//salesOrder.Lines = orders;
salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);
wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
if (wsDynamicsGP.State != CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
MessageBox.Show("Success");
lines = new SalesOrderLine[] { salesOrderLine }; will recreate the lines array object each time meaning you loose any previously added objects. Effectively only the final object in the loop is actually added.
Try using a List<T> like so:
SalesOrderLine[] lines = { }; Becomes List<SalesOrderLine> lines = new List<SalesOrderLine>();
lines = new SalesOrderLine[] { salesOrderLine }; Becomes: lines.Add(salesOrderLine);
If its important you end up with an array as the input:
salesOrder.Lines = lines; Becomes: salesOrder.Lines = lines.ToArray();
I have seen several questions about doing a custom tooltip for a single line series.
I need a custom tool-tip for each data-point. I would like to add more to the tool-tip than just the dependent value path and the independent value path.
Example I have 2 data points on the same line one with a value(Y-axis)
of 2, date(x-axis) of 4/28/2016, and configuration of A. The other has
a value of 3, date of 4/29/2016, and configuration of B.
How would I also show the configurations? This is all done in code behind because I have a dynamic number of lineseries. So I can't just assign a style to each lineseries in the xaml.
var MyLineSeries = new LineSeries();
lMyLineSeries.DependentValuePath = "Y";
lMyLineSeries.IndependentValuePath = "X";
lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;
This is my code for creating the tool tip style.
var lToolTipDataPointStyle = new Style(typeof(LineDataPoint));
var lTemplate = new ControlTemplate(typeof(LineDataPoint));
var lGridElement = new FrameworkElementFactory(typeof(Border));
//Tooltip
var lStackPanel = new StackPanel();
var lValueContentControl = new ContentControl();
lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath));
lValueContentControl.ContentStringFormat = "Value: {0}";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to???
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
lStackPanel.Children.Add(lValueContentControl);
lStackPanel.Children.Add(lConfigurationContentControl);
lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel);
var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse));
lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty));
lGridElement.AppendChild(lEllipseElement);
lTemplate.VisualTree = lGridElement;
var lTemplateSetter = new Setter();
lTemplateSetter.Property = LineDataPoint.TemplateProperty;
lTemplateSetter.Value = lTemplate;
lToolTipDataPointStyle.Setters.Add(lTemplateSetter);
return lToolTipDataPointStyle;
I figured it out by using the Tag on the Line series.
myLineSeries.Tag = "Configuration";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString()))
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
Even looking into MSDN's Exchange 2013 - 101 Code Samples, I could not find an example creating notes using EWS Managed API 2.0. On Folders and items in EWS in Exchange, the most appropriate item type seems to me PostItem but my test failed trying to create such items in Notes folder. Or, is it possible there is no API for creating notes in this library?
A PostItem isn't the same as a note in the Notes folder. PostItem's represent items with a message class of IPM.Post. Notes, on the other hand, use the message class IPM.StickyNote. The managed API has no direct support for these items. You can retrieve them as EmailMessage objects, and you can even create them as EmailMessage objects if you manually set the required properties. Glen has a good write-up on his blog: http://gsexdev.blogspot.com/2009/07/creating-sticky-notes-in-ews-managed.html
Take a look at the PostItem, they should do what you want. PostItem
Sample
var items = new List<PostItem>();
for (int i = 0; i != 10; ++i)
{
var m = new PostItem(service);
m.Subject = "Note " + i.ToString();
m.Body = new MessageBody(BodyType.Text, "A test note");
m.Save();
}
var guid = new Guid("0006200E-0000-0000-C000-000000000046");
var colour = new ExtendedPropertyDefinition(guid, 0x8B00, MapiPropertyType.Integer);
var width = new ExtendedPropertyDefinition(guid, 0x8B02, MapiPropertyType.Integer);
var height = new ExtendedPropertyDefinition(guid, 0x8B03, MapiPropertyType.Integer);
var left = new ExtendedPropertyDefinition(guid, 0x8B04, MapiPropertyType.Integer);
var top = new ExtendedPropertyDefinition(guid, 0x8B05, MapiPropertyType.Integer);
var items = new List<EmailMessage>();
for (int i = 0; i != maxItems; ++i)
{
var m = new EmailMessage(service);
m.Subject = "Note " + i.ToString();
m.ItemClass = "IPM.StickyNote";
m.Body = new MessageBody(BodyType.Text, "A test note");
m.SetExtendedProperty(colour, 1);
m.SetExtendedProperty(width, 200);
m.SetExtendedProperty(height, 166);
m.SetExtendedProperty(left, 200);
m.SetExtendedProperty(top, 200);
items.Add(m);
}
var folder = Folder.Bind(service, WellKnownFolderName.Notes, new PropertySet());
var responses = service.CreateItems(items, folder.Id, MessageDisposition.SaveOnly, SendInvitationsMode.SendToNone);
I am using ebay .Net SDK. Everything is working fine except following requirements:
Using of OutputSelector to boost performance
Unable to use SortingOrder, while showing records.
Total income/amount sold for specified time range i.e. Total amount across all calls of the pagination without looping through pages and aggregating it manually.
Here is the code which I am using:
var apicall = new GetOrdersCall(context);
//apicall.ApiRequest.OutputSelector = new StringCollection(new String[] { "Order.OrderID", "Order.Total" });
apicall.ApiRequest.Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
};
var fltr = new TimeFilter(Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"), Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"));
var statusCodeType = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]);
var orders = apicall.GetOrders(fltr, TradingRoleCodeType.Seller, statusCodeType);
Please assist me how to use these 3 functionality as well.
After much efforts I got the way for it:
var request = new GetOrdersRequestType
{
//OutputSelector = new StringCollection {"OrderID","Total"},
CreateTimeFrom = Convert.ToDateTime(Request.Form["dateFrom"] + "T00:00:00.000Z"),
CreateTimeTo = Convert.ToDateTime(Request.Form["dateTo"] + "T23:59:59.999Z"),
OrderStatus = (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), Request.Form["statusCode"]),
OrderRole = TradingRoleCodeType.Seller,
Pagination = new PaginationType
{
EntriesPerPage = Util.RecordsPerPage(),
PageNumber = int.Parse(Request.Form["pageNumber"])
}
};
var apicall = new GetOrdersCall(context)
{
ApiRequest = request,
OutputSelector =
new string[]
{
"OrderID", "Total", "PaidTime", "eBayPaymentStatus",
"PaymentMethod", "Title", "PageNumber", "PaginationResult.TotalNumberOfPages"
}
};
apicall.Execute();
var orders = apicall.ApiResponse.OrderArray;