我需要任何devexpress开发人员或任何能够了解它的人对这个问题有任何观点。
我有两种方法:
第一个从缓存变量中获取数据并将其加载到电子表格文档中
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
documentId = (String)Session["id"];
Spreadsheet.Open(documentId, DocumentFormat.Xlsx, () =>
{
return (byte[])Cache[documentId];
});
Cache.Remove(documentId);
Session.Remove("id");
}
}
我有上传事件的另一种方法,我从文件中获取数据并将其加载到电子表格文档中
protected void UploadControl_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e)
{
if (e.IsValid)
{
fileContent = e.UploadedFile.FileBytes;
documentFormat = GetFileExtension(e.UploadedFile.FileName);
documentId = Guid.NewGuid().ToString();
if (documentFormat != DocumentFormat.Undefined)
{
Spreadsheet.Open(documentId, documentFormat, () =>
{
return fileContent;
});
}
}
}
Page_Load Spreadsheet.Open函数运行正常。 UploadControl_FileUploadComplete中的另一个没有。
页面不会在上传事件之后或之前回发或刷新,而只是通过UploadControl_FileUploadComplete事件代码并执行它。
对此的任何评论或解决方法都会有所帮助
答案 0 :(得分:4)
ASPxUploadControl在回调上传文件。因此,可以在ASPxUploadControl的回调上更新其他控件。您需要处理客户端FileUploadComplete事件并在ASPxSpreadsheet上执行回调以打开上载的文件。要执行回调,请使用ASPxClientSpreadsheet.PerformCallback方法。然后,在您的服务器上处理ASPxSpreadsheet.Callback事件以打开您的文档。
<form id="form1" runat="server">
<div>
<dx:ASPxSpreadsheet ID="ASPxSpreadsheet1" ClientInstanceName="Spreadsheet1" runat="server" WorkDirectory="~/App_Data/WorkDirectory" OnCallback="ASPxSpreadsheet1_Callback"></dx:ASPxSpreadsheet>
<dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" UploadMode="Auto" Width="280px" OnFileUploadComplete="ASPxUploadControl1_FileUploadComplete" ShowUploadButton="True">
<ClientSideEvents FileUploadComplete="function(s, e) { OpenDocument(e.callbackData); }" />
</dx:ASPxUploadControl>
</div>
</form>
const string UploadDirectory = "~/UploadedFiles/";
protected void ASPxUploadControl1_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e) {
if (e.IsValid) {
string resultExtension = Path.GetExtension(e.UploadedFile.FileName);
string resultFileName = Path.ChangeExtension(Path.GetRandomFileName(), resultExtension);
string resultFileUrl = UploadDirectory + resultFileName;
string resultFilePath = MapPath(resultFileUrl);
e.UploadedFile.SaveAs(resultFilePath);
e.CallbackData = resultFilePath;
}
}
protected void ASPxSpreadsheet1_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e) {
ASPxSpreadsheet1.Open(e.Parameter);
}
<script type="text/javascript">
function OpenDocument(data) {
debugger
Spreadsheet1.PerformCallback(data);
}
</script>