导航:首页 > 版本升级 > net输出文本文件

net输出文本文件

发布时间:2024-04-21 16:26:25

A. 关于ASP.net 向客户端输出文件的问题

这是我做过的一个下载页面,不会另打开一个页面,也不会刷新,它用Response.Write直接向前台输出二进制。
源文件代码在这里,你应该看得懂吧。需要的命名空间,请你在VS的智能提示下补充上去。
string strPhyPath = Server.MapPath("~/")+ fileurl;//fileurl是文件的相对地址
if (File.Exists(strPhyPath))
{
//取文件大小
FileStream MyFileStream;
uint FileSize1;
MyFileStream = new FileStream(strPhyPath, FileMode.Open, FileAccess.Read, FileShare.None);
int iConverTemp = Convert.ToInt32(MyFileStream.Length);
FileSize1 = (uint)(iConverTemp);
MyFileStream.Close();

//存在,下载
Page.Response.ContentType = "APPLICATION/OCTET-STREAM";
Page.Response.AddHeader("Content-length", FileSize1.ToString());//下载文件长度
Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strPhyPath, System.Text.Encoding.UTF8));
Page.Response.WriteFile(strPhyPath);
Response.Flush();
Response.End();
}
else
{
this.Alert("文件不存在,请及时向管理员反馈!");//Alert是我自定义定义的方法
}

B. 在vb.net中如何生成一个txt文件,并且写入一个数组的值

已测试,代码如下:

ImportsSystem.IO'引入文本操作

PublicClassForm1

PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click

DimtxtAsString=Me.getTxt

SaveTxt(txt)

EndSub

'取得存储的文本

PrivateFunctiongetTxt()AsString

Dimx(0To10)AsInteger

ForiAsInteger=0Tox.Length-1

x(i)=CInt(100*Rnd())

Next

DimstrAsString=""

ForjAsInteger=0Tox.Length-1

str+=x(j).ToString&vbCrLf

Next

Returnstr

EndFunction

'存储文本

PrivateSubSaveTxt(ByValvAsString)

DimfpAsString=GetSavePath()

IfString.IsNullOrEmpty(fp)=FalseThen

'StreamWriter

DimSwriterAsNewStreamWriter(fp,False)'覆盖或新建

Swriter.WriteLine(v)

Swriter.Close()

EndIf

EndSub

'取得存储路径

PrivateFunctionGetSavePath()AsString

sd.FileName=""

sd.AddExtension=True

sd.DefaultExt="txt"

sd.Filter="TXT文件(*.txt)|*.txt"

sd.ShowDialog()

Returnsd.FileName

EndFunction

EndClass

测试截图如下。

C. 我要用C#,NET 导出一个word文档。文档内容只要一个表格。

楼上的 你能不能改写下这个例子啊? 我这个只能导出字符 不能导出表格
string title = "个人信息";
object titleLengh = title.Length;
string first = "\n 公司最近需要利用C#对项目进行编程,其" +
"中存在一个功能就是可自动生成WORD文档,但一直以来都" +
"找不到什么好办法,无奈之下,只有自已学着写一个了.";
object firstLengh = first.Length;
string second = "\n 如果能真正生成WORD文档的好处有:";
object secondLengh = second.Length;
string third = "\n1、根据数据库信息自动生成文档;";
object thirdLengh = third.Length;
string forth = "\n2、免去书写文档之苦;";
object forthLengh = forth.Length;
string fifth = "\n3、可以通过邮件方式传出文档。";
object fifthLengh = fifth.Length;
object missing;
object zero = 0;
object c = 10;
object one = 1;
object two = 2;
object tree = 3;
object four = 4;
object five = 5;
object six = 6;
object seven = 7;
object eight = 8;
object nine = 9;
object ten = 10;
Object Nothing = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Word.ApplicationClass wa = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = wa.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

missing = System.Reflection.Missing.Value;

wa.Visible = true;

wa.Documents.Add(ref missing, ref missing, ref missing, ref missing);

Microsoft.Office.Interop.Word.Range myRange = wa.ActiveDocument.Range(ref zero, ref zero);

object r = myRange;

Microsoft.Office.Interop.Word.Paragraph p = wa.ActiveDocument.Paragraphs.Add(ref r);

p.Range.InsertBefore(title);
//p.Range.Font.Size = 1;

Microsoft.Office.Interop.Word.Range titleRange = wa.ActiveDocument.Range(ref zero, ref titleLengh);

//titleRange.Font.Size = 1;
titleRange.Font.Name = "幼圆";

titleRange.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue;

//MessageBox.Show("NO.1");

//titleRange.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

Microsoft.Office.Interop.Word.Range firstR = wa.ActiveDocument.Paragraphs[1].Range;//.Item(2).Range;

Microsoft.Office.Interop.Word.Table table = WordDoc.Tables.Add(titleRange, 3, 3, ref Nothing, ref Nothing);

r = firstR;

p = wa.ActiveDocument.Paragraphs.Add(ref r);

firstR.Font.Size = 40;

firstR.Paragraphs.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

//在表格第一单元格中添加自定义的文字内容
table.Cell(1, 1).Range.Text = "lllll";

firstR.InsertAfter(first);

//firstR.InsertParagraphAfter();

//firstR=wa.ActiveDocument.Paragraphs.Item(3).Range;
firstR.InsertAfter(second);
firstR.InsertAfter(third);
firstR.InsertAfter(forth);
firstR.InsertAfter(fifth);

Context.Response.Write("成功");

D. 濡備綍鍦.net涓婃彁鍙朩ord锛孭d鐨勬枃鏈鍐呭

涓锛氬埄鐢╓ord閲岄潰鐨勨滅储寮曗濆姛鑳姐

1銆侀変腑闇瑕佹彁鍙栫殑鏂囧瓧锛屾墽琛岃彍鍗曞懡浠も滄彃鍏-寮曠敤-绱㈠紩鍜岀洰褰曗濓紱
2銆佸湪鈥滅储寮曗濋夐」椤甸噷闈㈤夋嫨鍗曞嚮鎸夐挳鈥滄爣璁扮储寮曢」鈥濓紱
3銆佹寚瀹氣滈夐」鈥濅负鈥滃綋鍓嶉〉鈥濓紝鏍规嵁闇瑕佸彲浠ユ寚瀹氭彁鍙栦箣鍚庢樉绀虹殑椤电爜鏍煎紡涓哄姞绮楁垨鑰呭炬枩锛屽崟鍑烩滄爣璁扳濓紱
4銆佹ゆ椂鏍囪扮储寮曢」绐楀彛骞朵笉浼氬叧闂锛岃屼笖浣犺繕鑳藉湪鏂囨。涓鎵惧埌骞堕変腑涓嬩竴涓闇瑕佹彁鍙栫殑鏂囧瓧锛岄噸澶嶆ラ3锛
5銆佸傛灉娌℃湁鍏跺畠闇瑕佹彁鍙栫殑鏂囧瓧浜嗭紝鍗曞嚮鈥滃叧闂鈥濓紱
6銆佸湪闇瑕佹彃鍏ョ储寮曡〃鐨勫湴鏂癸紝鎵ц岃彍鍗曞懡浠も滄彃鍏-寮曠敤-绱㈠紩鍜岀洰褰曗濓紝鏍规嵁闇瑕佽剧疆绱㈠紩琛ㄧ殑鏍煎紡锛堟瘮濡傚垎鏍忋佸归綈銆佺缉杩涚瓑椋庢牸锛夛紝鐒跺悗鍗曞嚮鈥滅‘瀹氣濄

杩欐牱鎵鏈夋爣璁拌繃绱㈠紩鐨勬枃瀛椾互鍙婂畠浠鎵鍦ㄧ殑椤电爜灏遍兘鎻愬彇鍑烘潵浜嗐

濡傛灉闇瑕佹彁鍙栫殑鏂囧瓧鏈夊緢澶氾紝閭d箞鎴栬镐篃鍙浠ョ敤VBA瀹忔潵鑷鍔ㄦ爣璁扮储寮曪紙鍗崇浉褰撲簬鑷鍔ㄥ畬鎴愪笂闈㈢殑1-5姝ラわ級銆備絾鏄鍓嶆彁鏄杩欎簺鏂囧瓧蹇呴』閮芥湁闈炲父鐗瑰畾鐨勬牸寮忥紝鍗冲彲浠ヤ繚璇佸綋鍓嶆枃妗d腑鍑℃槸鍏锋湁杩欎釜鏍煎紡鐨勬枃鏈锛岄兘鏄闇瑕佹彁鍙栫储寮曠殑鏂囨湰銆

浜岋細涓嬪垪VBA浠g爜鍙浠ヨ嚜鍔ㄤ负褰撳墠鏂囨。涓鐨勬墍鏈夌孩鑹叉枃瀛楀缓绔嬬储寮曟潯鐩锛屽苟鍦ㄥ綋鍓嶅厜鏍囦綅缃澶勬彃鍏ュ甫鏂囧瓧鏉$洰浠ュ強瀵瑰簲椤电爜鐨勭储寮曡〃锛

Option Explicit

Sub AutoMarkIndexForAllRedText()

Dim oSaveSelection As Range

Set oSaveSelection = Selection.Range

Selection.StartOf wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorRed ' 鍦ㄨ繖閲屽彲浠ヨ剧疆鏇村氱殑鍖归厤鏍煎紡锛屽傚瓧浣撱佸瓧鍙风瓑
While Selection.Find.Execute(FindText:="", Forward:=True, Format:=True)
ActiveDocument.Indexes.MarkEntry(Selection.Range, Selection.Range.Text).Select
Selection.Collapse wdCollapseEnd
Wend

oSaveSelection.Select
ActiveDocument.Indexes.Add Selection.Range

MsgBox "瀹屾垚锛"

End Sub

濡傛灉妤间富瀵逛簬杩欎釜浠g爜鐢熸垚鐨勭储寮曡〃鏍峰紡涓嶅お婊℃剰锛屼篃娌″叧绯汇傚洜涓虹幇鍦ㄦ墍鏈夌储寮曟潯鐩宸茬粡寤哄ソ锛屾墍浠ュ彧闇鎶婅嚜鍔ㄧ敓鎴愮殑绱㈠紩琛ㄥ垹闄ゅ悗鐢╓ord鑷宸辩殑鈥滄彃鍏-寮曠敤-绱㈠紩鍜岀洰褰曗濆懡浠ゆ潵閲嶆柊鐢熸垚绗﹀悎鑷宸辫佹眰鏍峰紡鐨勭储寮曡〃鍗冲彲銆

E. .net winfrom绋嬪簭鎬庝箞鎶婁竴涓椤甸潰瀵煎嚭瀛樹负word鏂囨。

//C#瀵煎嚭Word
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingWord=Microsoft.Office.Interop.Word;
usingSystem.Reflection;
usingSystem.Data;

namespaceExportTest
{
///<summary>
///瀵煎嚭word
///</summary>
publicclassExportWord
{
///<summary>
///灏嗘暟鎹琛ㄥ煎嚭鍒皐ord
///</summary>
///<paramname="dt">鏁版嵁琛</param>
///<paramname="isShowWord">鏄鍚︽樉绀簑ord</param>
///<paramname="fileName">瀵煎嚭鍒版枃浠跺悕</param>
///<paramname="picName">瀵煎嚭鍒皐ord涓鍥剧墖鍚</param>
///<returns></returns>
publicstaticboolExportToWord(DataTabledt,boolisShowWord,objectfileName,stringpicName)
{
if(System.IO.File.Exists(fileName.ToString()))
{
System.IO.File.Delete(fileName.ToString());
}
boolresult=true;

Objectmyobj=Missing.Value;;
if(dt==null||dt.Rows.Count==0)
{
result=false;
}
else
{
//寤虹珛Word搴旂敤
Word.Applicationword=newWord.Application();

//word鏂囨。
Word.Documentmydoc=newWord.Document();
mydoc=word.Documents.Add(refmyobj,refmyobj,refmyobj,refmyobj);
word.Visible=isShowWord;
mydoc.Select();

Word.Selectionmysel=word.Selection;

//mysel.InlineShapes.AddPicture(picName,refmyobj,refmyobj,refmyobj);
objecttop=100;
objectleft=300;
objecthw=100;


//灏嗘暟鎹鐢熸垚Word琛ㄦ牸鏂囦欢
Word.Tablemytable=mydoc.Tables.Add(mysel.Range,dt.Rows.Count,dt.Columns.Count,refmyobj,refmyobj);

//璁剧疆鍒楀
mytable.Columns.SetWidth(50,Word.WdRulerStyle.wdAdjustNone);

//杈撳嚭鍒楁爣棰樻暟鎹
for(inti=0;i<dt.Columns.Count;i++)
{
mytable.Cell(1,i+1).Range.InsertAfter(dt.Columns[i].ColumnName);
}
//杈撳嚭鎺т欢涓鐨勮板綍
for(inti=0;i<dt.Rows.Count-1;i++)
{
for(intj=0;j<dt.Columns.Count;j++)
{
mytable.Cell(i+2,j+1).Range.InsertAfter(dt.Rows[i][j].ToString());
}
}

mydoc.Shapes.AddPicture(picName,refmyobj,refmyobj,refleft,reftop,refhw,refhw,refmyobj);

//淇濆瓨鏂囨湰
mydoc.SaveAs(reffileName,refmyobj,refmyobj,refmyobj,refmyobj,refmyobj,
refmyobj,refmyobj,refmyobj,refmyobj,refmyobj,refmyobj,
refmyobj,refmyobj,refmyobj,refmyobj);
}

returnresult;
}

}

阅读全文

与net输出文本文件相关的资料

热点内容
编程如何让人物重复发射子弹 浏览:853
db2查看表空间文件 浏览:607
ps文件界面设置 浏览:779
c语言12位的数据应该怎么存储 浏览:953
将ape导入iphone 浏览:107
js组合快捷键 浏览:174
linux系统盘默认挂在的文件夹 浏览:667
淘宝数据包如何操作上架 浏览:567
vb编程中输入cls是什么意思 浏览:81
linuxtime服务 浏览:184
疯狂安卓讲义第二版代码 浏览:420
老炮儿三小时版本下载 浏览:313
matlab怎么调试程序 浏览:2
winxp升级win7的危害 浏览:496
网络没连上却不可用是怎么回事 浏览:752
社区版本 浏览:738
怎么查微信公众号什么时候开通的 浏览:717
安装三菱编程闪退怎么回事 浏览:488
手机怎么创建word文件格式 浏览:694
c语言连接数据库 浏览:887

友情链接