基本信息
源码名称:C# 取出Resources中的Excel/Word檔來使用(ResourceManager)
源码大小:0.01M
文件格式:.rar
开发语言:C#
更新时间:2016-07-02
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
取出Resources中的Excel/Word檔來使用
取出Resources中的Excel/Word檔來使用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace OutputResXls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
byte[] sampleXls = Properties.Resources.sample; //取出Resources中的sample.xls檔
FileStream outputExcelFile = new FileStream("C:\\sample.xls", FileMode.Create, FileAccess.Write); //存到C槽
outputExcelFile.Write(sampleXls, 0, sampleXls.Length);
outputExcelFile.Close();
}
private void button2_Click(object sender, EventArgs e)
{
string tmpFile = Path.GetTempFileName(); //取一個不重複的暫存檔名 (副檔名.tmp)
byte[] sampleXls = Properties.Resources.sample;
FileStream outputExcelFile = new FileStream(tmpFile, FileMode.Create, FileAccess.Write); //存到temp檔
outputExcelFile.Write(sampleXls, 0, sampleXls.Length);
outputExcelFile.Close();
string xlsFile = Path.ChangeExtension(tmpFile, "xls"); //變更副檔名為.xls
File.Move(tmpFile, xlsFile);
MessageBox.Show("存到[" xlsFile "]成功");
}
}
}