Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

asp.net DataGridViewµ¼³öµ½ExcelµÄÈý¸ö·½·¨

http://hi.baidu.com/%E5%EB%B3%DF%C8%CB%C9%FA/blog/item/58a1540bbf0bb437b1351d9a.html
#region DataGridViewÊý¾ÝÏÔʾµ½Excel
/// <summary>
/// ´ò¿ªExcel²¢½«DataGridView¿Ø¼þÖÐÊý¾Ýµ¼³öµ½Excel
/// </summary>
/// <param name="dgv">DataGridView¶ÔÏó </param>
/// <param name="isShowExcle">ÊÇ·ñÏÔʾExcel½çÃæ </param>
/// <remarks>
/// add com "Microsoft Excel 11.0 Object Library"
/// using Excel=Microsoft.Office.Interop.Excel;
/// </remarks>
/// <returns> </returns>
public bool DataGridviewShowToExcel(DataGridView dgv, bool isShowExcle)
{
if (dgv.Rows.Count == 0)
return false;
//½¨Á¢Excel¶ÔÏó
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = isShowExcle;
//Éú³É×Ö¶ÎÃû³Æ
for (int i = 0; i < dgv.ColumnCount; i++)
{
excel.Cells[1, i + 1] = dgv.Columns[i].HeaderText;
}
//Ìî³äÊý¾Ý
for (int i = 0; i < dgv.RowCount - 1; i++)
{
for (int j = 0; j < dgv.ColumnCount; j++)
{
if (dgv[j, i].ValueType == typeof(string))
{
excel.Cells[i + 2, j + 1] = "'" + dgv[j, i].Value.ToString();
}
else
{
excel.Cells[i + 2, j + 1] = dgv[j, i].Value.ToString();
}
}
}
return true;
}
#endregion
#region DateGridViewµ¼³öµ½csv¸ñʽµÄExcel
/// <summary>
/// ³£Ó÷½·¨£¬ÁÐÖ®¼ä¼Ó\t£¬Ò»ÐÐÒ»ÐÐÊä³ö£¬´ËÎļþÆäʵÊÇcsvÎļþ£¬²»¹ýĬÈÏ¿ÉÒÔµ±³ÉExcel´ò¿ª¡£
/// </summary>
/// <remarks>
/// using System.IO;
/// </remarks>
/// <param name="dgv"></param>
private void DataGridViewToExcel(DataGridView dgv)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "Execl files (*.xls)|*.xls";
dlg.FilterIndex = 0;
dlg.RestoreDirectory = true;
dlg.CreatePrompt = true;
dlg.Title = "±£´æΪExcelÎļþ";
if (dlg.ShowDialog() == DialogResult.OK)
{
Stream myStream;
myStream = dlg.OpenFile();
StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding


Ïà¹ØÎĵµ£º

asp.net ¶ÁÈëhtmlÎļþÌæ»»

csÎļþ£º
using System.IO;
string context = "";
string path = HttpContext.Current.Server.MapPath("") + "\\test\\test.html";
 System.Text.Encoding code = System.Text.Encoding.GetEncoding("utf-8");
                Stre ......

ASP.NET ÕýÔò±í´ïʽÇå³ýHTML´úÂë

public string ClearHtml(string HtmlStr)
{
string tmpStr = HtmlStr;
tmpStr = ReplaceHtml("&#[^>]*;", tmpStr, "");
tmpStr = ReplaceHtml("</?marquee[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?object[^>]*>", tmpStr, "");
tmpSt ......

asp.net»ñÈ¡Õæʵip

public string getip()
    {
        string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (null == result || result == String.Empty)
       ......

asp.netÖÐSystem.DateTime.Now.ToString()µÄһЩÓ÷¨


Asp.netÖеÄÈÕÆÚ´¦Àíº¯Êý
     //2007Äê4ÔÂ24ÈÕ
     this.TextBox6.Text = System.DateTime.Now.ToString("D");
     //2007-4-24
     this.TextBox7.Text = System.DateTime.Now.ToString("d");
 &nb ......

asp.netÓï¾ä

   1¡¢¿ØÖÆGridView¿Ø¼þÖÐÄÚÈݵĻ»ÐÐ
GridView1.Attributes.Add("style","word-break:keep-all;word-wrap:normal");//Õý³£»»ÐÐ
GridView1.Attributes.Add("style","word-break:break-all;word-wrap:break-word");//×Ô¶¯»»ÐÐ
2¡¢É¾³ýGridView¿Ø¼þÐÐÐÅÏ¢µ¯³öÈ·ÈÏÌáʾ¿ò
ÔÚGridViewµÄRowDataBound()ʼþÖÐÌ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ