Google表格SortSpecs [英] Google Sheets SortSpecs
问题描述
我正在尝试为Google表格创建请求,但我遇到了sortSpecs方法的问题。
var test = new请求()
{
SortRange = new SortRangeRequest()
{
Range = new GridRange()
{
SheetId = 0,
StartRowIndex = 1
},
SortSpecs = new SortSpec()
{
SortOrder =ASCENDING,
DimensionIndex = 0
}
}
};
当使用这个时,除了SortSpec,一切正常。 Visual Studio提供了错误:
lockquote
无法将类型'Google.Apis.Sheets.v4.Data.SortSpec'
隐式转换为
System.Collections.Generic.IList'
存在显式转换
更新: strong>
没有更多的构建错误,但现在执行代码时出现另一个错误。
List< Data.Request> requests = new List< Data.Request>(); // TODO:更新占位符值。
Data.SortSpec so = new Data.SortSpec();
so.SortOrder =ASCENDING;
Data.SortSpec di = new Data.SortSpec();
di.DimensionIndex = 0;
列表< Data.SortSpec> ss = new List< Data.SortSpec>();
ss.Add(so);
ss.Add(di);
var test = new Request()
{
SortRange = new SortRangeRequest()
{
Range = new GridRange()
{
SheetId = 0,
StartRowIndex = 1
},
SortSpecs = ss
}
};
requests.Add(test);
给出的例外是
消息[无效请求[0] .sortRange:未指定排序顺序。]位置[ - ]原因[badRequest]域[global]
根据参考文档, SortSpecs
是项目列表,而不是单个项目。该错误消息也是说(它不能将SortSpec转换为IList)。如果您想为排序规范使用单个SortSpec,请创建一个列表,将该单个项目放入其中,并将 SortSpecs
分配给该列表。
I'm trying to create a request for Google Sheets, but I'm having problems with the sortSpecs method.
var test = new Request()
{
SortRange = new SortRangeRequest()
{
Range = new GridRange()
{
SheetId = 0,
StartRowIndex = 1
},
SortSpecs = new SortSpec()
{
SortOrder = "ASCENDING",
DimensionIndex = 0
}
}
};
When using this, everything works correctly except for the SortSpec. Visual Studio gives the error:
Cannot implicitly convert type 'Google.Apis.Sheets.v4.Data.SortSpec' to System.Collections.Generic.IList' An explicit conversion exists
UPDATE:
There are no more build errors, but now I have another error when executing the code.
List<Data.Request> requests = new List<Data.Request>(); // TODO: Update placeholder value.
Data.SortSpec so = new Data.SortSpec();
so.SortOrder = "ASCENDING";
Data.SortSpec di = new Data.SortSpec();
di.DimensionIndex = 0;
List<Data.SortSpec> ss = new List<Data.SortSpec>();
ss.Add(so);
ss.Add(di);
var test = new Request()
{
SortRange = new SortRangeRequest()
{
Range = new GridRange()
{
SheetId = 0,
StartRowIndex = 1
},
SortSpecs = ss
}
};
requests.Add(test);
The exception given is
Message[Invalid requests[0].sortRange: No sort order specified.] Location[ - ] Reason[badRequest] Domain[global]
Per the reference docs, SortSpecs
is a list of items, not a single item. The error message is also saying that (it can't convert SortSpec to an IList). If you want to use a single SortSpec for your sorting specifications, create a list, put that single item in it, and assign SortSpecs
to that list.
这篇关于Google表格SortSpecs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!