我正在使用EPPlus创建/发送文件,如下所示:
using (ExcelPackage package = new ExcelPackage())
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet");
... //create file here
Response.Clear();
Response.ContentType = "application/xlsx";
Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".xlsx");
Response.BinaryWrite(package.GetAsByteArray());
Response.End();
}
Run Code Online (Sandbox Code Playgroud)
一切正常,除了文件总是以只读方式返回,我无法弄清楚原因.在"package"对象中,有一个带有IsReadOnly字段的文件对象,但文件对象为null.我预计我没有正确创建xcel文件,但这是我弄清楚如何创建文件的唯一方法.最初我使用的是内存流,但是这样做,当excel文件大于50行时,我遇到了问题.
编辑/更新:所以我通过单击"下载为Excel文件"按钮启动代码块.代码运行,创建文件,并提示用户"你已经选择打开:thisismyexcelfile.xlsx这是:XLSX文件(此处大小)来自:mywebsite.firefox应该对此文件做什么?" 选择"使用OpenOffice Calc打开"后,spreedsheet将打开并正确显示,但它是只读的.
编辑/更新:我使用OpenOffice检查了文件属性.在"属性/安全性"下,有一个"打开文件只读"复选框,但它已被取消选中并禁用.
如何将数据集作为 CSV 文件保存到客户端电脑?
我可以将文件从服务器保存到客户端电脑,我可以将数据表转换为 CSV 文件,但我似乎无法弄清楚如何将两者放在一起。
将文件从服务器保存到客户端(作为附件)
String FileName = "my file name";
String FilePath = @"C:\testfile.txt";
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath + FileName); //Can only put the file path in here, cant put the datatable or convertion in there..
response.Flush();
response.End();
Run Code Online (Sandbox Code Playgroud)
将数据表转换为 CSV 文件(因为我有一个应作为 CSV 文件保存到客户端电脑的数据表)
StringBuilder sb = new StringBuilder();
string[] columnNames = dt.Columns.Cast<DataColumn>().
Select(column => column.ColumnName).
ToArray();
sb.AppendLine(string.Join(",", columnNames));
foreach (DataRow row in dt.Rows)
{ …Run Code Online (Sandbox Code Playgroud) 在处理这段代码一段时间之后,我几乎遇到了一个意外的问题。当将选项“ B”和“ C”作为用户输入键入时,if和else语句在屏幕上不显示任何内容。我已经尝试了一些方法,但是似乎无法弄清楚。
import java.util.Scanner;
public class Internet_Service_Provider
{
public static void main(String[] args)
{
double hours;
char choice;
Scanner input = new Scanner(System.in);
System.out.println ("Enter the letter of your package: ");
choice = input.nextLine().charAt(0);
System.out.println ("Enter the number of hours used: ");
hours = input.nextDouble();
double chargesa, chargesb, chargesc;
chargesa = 9.95;
chargesb = 13.95;
chargesc = 19.95;
double chargesa2, chargesb2;
chargesa2 = (hours - 10) * 2;
chargesb2 = (hours - 20);
double extrafeesA, extrafeesB;
extrafeesA = chargesa …Run Code Online (Sandbox Code Playgroud) 好的,我正在尝试将加密文本写入文件.
由于某种原因,我得到一个未在此范围内声明编译错误.
这是我的encryption.cpp文件:
#include <iostream>
#include <fstream>
#include <string>
class encrypt{
public:
static void cryptText(std::string newpass)
{
int x = newpass.size();
int output[x -1];
for(int i = 0; i <= x -1; i++)
{
output[i] = (int)newpass[i];
std::cout << char(output[i] + x);
//Here I am trying to write output onto the file. For some reason, though,
//I get the error.
myfile.open ("passwords.thaddeus");
myfile << output << std::endl;
myfile.close();
}
std::cout << std::endl;
}
};
Run Code Online (Sandbox Code Playgroud)
我查看了带文件的输入/输出的cplusplus.com文档.我将他们的示例程序复制到Code :: Blocks中,它运行得很好.但是当我尝试它时,我得到了错误.这很奇怪,因为我包括在内.
我是一个相当有经验的C#程序员,并试图用一个创建Stack对象的C++应用程序来帮助一个朋友.自从我看到C++以来,我已经有超过13年的时间了,我正试着回忆起正确的方法.我花了一些时间再次加快了Header/CPP的区别,所以甚至可能存在问题.这是我的问题:
//Stack.h
#ifndef __STACK_INCLUDED__
#define __STACK_INCLUDED__
#include "Node.h"
class Stack
{
private:
/// Going to be the pointer to our top node
Node* m_topNode;
/// Running count of elements
int m_count;
public:
///Constructor
Stack();
///Allows us to retrieve the top value from the stack
/// and remove it from the stack
int Pop();
.
.
.
};
#endif
Run Code Online (Sandbox Code Playgroud)
以下是与标题匹配的CPP.我现在正在这里进行调试.我也完全符合条件,因为我不确定这是否会引起指针问题和参考文献丢失.
//Stack.cpp
#include "stdafx.h"
#include "Stack.h"
#include <iostream>
Stack::Stack(){
m_count = 0;
m_topNode = NULL;
}
void Stack::Push(int Value){
std::cout << "\nPushing …Run Code Online (Sandbox Code Playgroud) 在构造函数中我做了:
mouseState = Mouse.GetState();
var mousePosition = new Point(mouseState.X, mouseState.Y);
Run Code Online (Sandbox Code Playgroud)
然后在我创建的输入法中添加了:
private void ProcessInput(float amount)
{
Vector3 moveVector = new Vector3(0, 0, 0);
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.W))
moveVector += new Vector3(0, 0, -1);
if (keyState.IsKeyDown(Keys.Down) || keyState.IsKeyDown(Keys.S))
moveVector += new Vector3(0, 0, 1);
if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.D))
moveVector += new Vector3(1, 0, 0);
if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.A))
moveVector += new Vector3(-1, 0, 0);
if (keyState.IsKeyDown(Keys.Q))
moveVector += new Vector3(0, 1, 0);
if (keyState.IsKeyDown(Keys.Z))
moveVector += new …Run Code Online (Sandbox Code Playgroud) C#中类的默认Access修饰符是internal.但是在使用ildasm检查类时,它将类显示为私有.
.class private auto ansi beforefieldinit ConsoleApplication1.Program
extends [mscorlib]System.Object
{
} // end of class ConsoleApplication1.Program
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
在我的项目中,我有一个与时间一起工作的类,它被声明为:
class Data {
int dia;
int mes;
int ano;
int hora;
int minuto;
public:
Data();
Data(int, int, int, int, int);
Data(const Data &);
void mostraData();
void ImprimeData();
Data operator-(const Data &aux);
};
Run Code Online (Sandbox Code Playgroud)
dia = day,mes = month,ano = year,hora = hour ....(葡萄牙语)
在某些时候,我必须计算两个不同时间之间的差异.所以我做了这个简单的操作符 - :
Data Data::operator-(const Data & aux){
Data temp(0, 0, 0, 0, 0);
temp.dia = this->dia - aux.dia;
temp.mes = this->mes - aux.mes;
temp.ano = this->ano - aux.ano;
temp.hora = this->hora - aux.hora;
temp.minuto = this->minuto …Run Code Online (Sandbox Code Playgroud) 我正在尝试计算ID为3的DataList中的行,并将值放在标签中.
for (int i = 0; i < Product.Items.Count; ++i)
{
if (table.Rows[i]["id"].ToString() == "3")
{
int x = x + 1;
lblCounter.text = x.ToString
}
}
Run Code Online (Sandbox Code Playgroud)