���D�y�z :
���`���p�U�{�����i���`�B�@
��ɭԷ|�� COM Error �����p�o�� (�o�Ͱ��D����)
�? Error �o�ͮ� �{���N�|���Catch���@�q��X Error Message
�{�b�����D�O�p��b Error Processing (�Y Catch ��)�[�W���� COM Object���{��
��Y�κ��а_�Ө��@�q
�p�G�����[���@�q�S���ܪ���
�|���ͧ䤣���ܼƪ���~
�аݸӦp��B�z�O
[Defauls.aspx.cs]
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
string InputFile = Request.QueryString["file_name"];
string DateStr = "_"+Request.QueryString["date_str"];
string ProcessMode = Request.QueryString["mode"];
string OutputFile = InputFile.Replace(DateStr, "");
string FilePath = "F:\\excel_process\\"+InputFile;
if (!System.IO.File.Exists(FilePath))
{
Response.Write("<script language=\"javascript\">\n");
Response.Write("alert(\"Internal Error!!\");\n");
Response.Write("</script>\n");
return;
}
Microsoft.Office.Interop.Excel.Application xlApp =
new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook xlBook =
xlApp.Workbooks.Open(FilePath);
Microsoft.Office.Interop.Excel.Worksheet xlSheet =
(Microsoft.Office.Interop.Excel.Worksheet)xlBook.Worksheets.Item[1];
string SaveFilePath = "F:\\excel_process\\" +OutputFile;
xlBook.SaveAs(SaveFilePath);
[1;32;40m//close all object Start
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
xlSheet = null;
xlBook.Close(false, Type.Missing, Type.Missing);
xlApp.Workbooks.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
xlBook = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp.Workbooks);
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
xlApp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
//close all object end
[0;37;40m
if ((ProcessMode == "")||(ProcessMode == null))
{
Response.AppendHeader("Content-Type", "application/X-MS-Excel;");
Response.AppendHeader("Content-Disposition",
"attachment; filename=" + OutputFile);
Response.WriteFile(SaveFilePath);
}
}
catch (Exception error_msg)
{
Response.Write("<BR>[Error]<BR>" + error_msg.ToString());
}
}
}
}
[Default.aspx]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
--
�� �o�H��: �����~�{(ptt.cc)
�� From: 118.169.184.146
�� �s��: cyril63 �Ӧ�: 118.169.184.146 (11/23 14:29)
2. ����s��
http://social.msdn.microsoft.com/Search/zh-TW/?Refinement=112&query=%u5ef6%u5f8c%u9023%u7d50
3. MIME
http://social.msdn.microsoft.com/Search/zh-TW/?Refinement=112&query=Excel%20MIME
==> ����� "... <cyril...@ptt.cc>"
> �� news:4j7cR4%2485f%40ptt.cc �o��
> �{���\�� : (�p�H�U�{����q)
--
���������Ҧ������q ASP.NET Web News Reader 0.2.9 UTF-8 Beta
�����a�� http://tlcheng.twbbs.org/wwwmap.htm
�y�쨾�x/�ϰ���귽/�}�@��/������/�y���q�T �峹�P�{��
Basic/Fortran/Windows API/.Net/���U������ ��l�X�B�峹�P�Q��
�L�n�{���]�p�B�t�κz�ϥηs�N�°Q�װϡA���ͦ^�Ы�Y��²�T�B�q�l�l��q���G
MSDN: http://social.msdn.microsoft.com/Forums/zh-TW/categories/
TechNet: http://social.technet.microsoft.com/Forums/zh-TW/categories/
--
ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx
RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=tw.bbs.comp.language