|
did not completly understand your word. can u give me any sample code to convert:
txt to xls
OR
txt to CSV to xls
accually data goes like this:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
the above is a variable row, so that set of row should be stored on perticular cell on xls. then the next set of rows should be stored on next perticular set of cells.
|
|
|
|
|
if a simple CSV import doesn't do what you want, then you will need to use the Office Primary Interop Assemblies[^]. I trust CodeProject holds some example articles on the subject. I've never used it myself.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
taurusone wrote: can anyone give me a C# code which does this.
This is a site for programmers - not a restaurant where you can order stuff.
Create a CSV file, open it in Excel. You'll see that it simply opens the CSV file, and treats it whether it was a regular Excel-file. That means that you can concatenate all your files into a single string, separated by comma's, and write it to a CSV.
Bastard Programmer from Hell
|
|
|
|
|
yes i know it is not restaurant and i am not ordering, it a request.
input file:
table 1:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
table 2:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
txt4 txt3 txt2 txt1
txt4 txt3 txt2 txt1
note that the table rows or variging. i want to write a code which
wanted output xls file:
table 1:
sume of first col: sum of say 3rd col:
txt1 txt3
txt5 txt7
txt4 txt2
table2: <same as above>
Plz dont misunderstand me point me to site which has c# code to do this or atleast give me an overview or idea about implenting this in c#.
|
|
|
|
|
taurusone wrote: yes i know it is not restaurant and i am not ordering, it a request.
Aight, we'll walk you through it, from start to finish. Can you paste the sourcecode to read/write a textfile here? Once you got that, you're halfway.
taurusone wrote: Plz dont misunderstand me point me to site which has c# code to do this or atleast give me an overview or idea about implenting this in c#.
Luc gave you an idea, even though it requires some basic programming-skills. There's little chance that anyone will post code "at request" that does "what I want".
..but we can walk you trough writing such a thing. Seems the best idea, as that'd mean that you'll understand every line of code, and will be able to change it when required. So, let's see your code on reading/writing text files
Bastard Programmer from Hell
|
|
|
|
|
So you want the first and third columns only.
So write a program that extracts the first and third columns and write those to a text file.
Then you can use excel to open the file using a CSV format. Excel actually allows for a choice of what is used as a separator. Myself I use tab.
|
|
|
|
|
This article[^] will show you how to do it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Hi all
I am creating a software that contains a dynamic chart showing temperature and depth . The temperature varies all the time in the time .I use a usercontrol that has several colors(gradient).For example the 30 degree has been shown as Red and as the temperature decreases it will change to Blue.Now i am using static gradient . Now i need to update as the temperature changes the gradiant must also be changed according to the value of the temperature.
that is if the temperature suddenly falls from 30 degree to 5 degree the color must have to change from Red to Blue.
|
|
|
|
|
The quickest and dirtiest way (and I am assuming you are using binding here) would be to have a custom converter class which accepts the temperature as an input, and returns the relevant colour as the output. What you need to look at is implementing an IValueConverter - and hook this up in a binding. For instance:
BackgroundColor="{Binding Temperature, Converter={StaticResource myTemperatureToColorConverter}}" Note that you would have to add a reference to your colour converter in a resources section like this:
<converters:TemperatureToColorConverter x:Key="myTemperatureToColorConverter" /> I leave the actual implementation of the converter class to you, but you should find plenty of source samples on the web, as this is a very trivial task.
BTW - don't surround your text in the <pre> tags, these should be reserved for code samples.
Second BTW - you should have asked this in the WPF forum.
|
|
|
|
|
Hi
I used Ado.Net entity framework to create a model with just one simple entity which has only one property Name.
So I use the wizard, classes were created fine.
<pre> [EdmEntityTypeAttribute(NamespaceName="ModelStart", Name="tableA")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class tableA : EntityObject
{
--some code here
I have tried to serialize the object I have binary with the code:
using (ModelStartContainer model= new ModelStartContainer())
{
BinaryFormatter bf = new BinaryFormatter();
try
{
var query = model.tableAs;
FileStream filestream = new FileStream(@"c:\Serialize\conTemp.dat", FileMode.Create);
bf.Serialize(filestream, query);
filestream.Close();
}
catch (EntitySqlException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (EntityCommandExecutionException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (SerializationException ex)
{
throw new ApplicationException("The object graph could not be serialized", ex);
}
}
My problem is I get Exception
SerializationException
that the object is not marked as serializable, but it is.
{"Type 'System.Data.Objects.ObjectSet`1[[entityMapExample.tableA, entityMapExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."}
Where is my mistake here?
|
|
|
|
|
Just because you have marked a class as Serializable , this doesn't guarantee that it actually is serializable. If one of the types in the class is not serializable, for instance, then you cannot serialize the object. The exception here is saying that ObjectSet is not serializable.
|
|
|
|
|
ok, I see my Entity class inherits from EntityObject
which has a StructuralObject member with an instance Object inside.
What can I do to make it serialize.
This Object should be also serialized or I don't need it?
|
|
|
|
|
I would suspect that the issue is more that something in your class is not serializable. Is there an InnerException that you can inspect? That will contain more information.
|
|
|
|
|
Inner exception
{"Type 'System.Data.Objects.ObjectSet`1[[entityMapExample.tableA, entityMapExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."}
Data
{System.Collections.ListDictionaryInternal}
StackTrace
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at entityMapExample.Program.Main() in C:\C#projetcs\entityMapExample\entityMapExample\Program.cs:line 39
and here is my class:
[EdmEntityTypeAttribute(NamespaceName="ModelStart", Name="tableA")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class tableA : EntityObject
{
#region Factory Method
public static tableA CreatetableA(global::System.Int32 id, global::System.String name)
{
tableA tableA = new tableA();
tableA.Id = id;
tableA.Name = name;
return tableA;
}
#endregion
#region Primitive Properties
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 Id
{
get
{
return _Id;
}
set
{
if (_Id != value)
{
OnIdChanging(value);
ReportPropertyChanging("Id");
_Id = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Id");
OnIdChanged();
}
}
}
private global::System.Int32 _Id;
partial void OnIdChanging(global::System.Int32 value);
partial void OnIdChanged();
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Name
{
get
{
return _Name;
}
set
{
OnNameChanging(value);
ReportPropertyChanging("Name");
_Name = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Name");
OnNameChanged();
}
}
private global::System.String _Name;
partial void OnNameChanging(global::System.String value);
partial void OnNameChanged();
#endregion
}
|
|
|
|
|
I think BinarySerialization does not work with EntityObject. You can try to use XmlSerialization. ord you try to Use POCO (Not derived from EntityObject) for BinarySerialization.
|
|
|
|
|
I want to serialize as XML.
the problem is it does not serialize references.
(other tables with foreign keys).
I am wondering if I create an addition property in my Entity class to take all references and GET it as an Array or List; mark it as [DataMemberAttribute()]; it will serialize
The only problem is when deserializing I have to manuly reload the collection into the Reference (foreign key).
Which solution do you think is easear to serialize objects togheter with references?
|
|
|
|
|
I was able to serialize also with references in this way:
but still I dont understand why when using a DataContractSerializer I am able to serialize also the references since it is mark as xmlIgnore
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("ModelStart", "PlayerHobbie", "Hobbie")]
public EntityCollection<Hobbie> Hobbies
{
let's see when deserializing ...
using (ModelStartContainer model= new ModelStartContainer())
{
try
{
var queryable = model.Players.Include("Hobbies").ToList();
using (XmlWriter writer = XmlWriter.Create(@"c:\Serialize\conTemp.xml"))
{
DataContractSerializer serializer = new DataContractSerializer(queryable.GetType());
serializer.WriteObject(writer, queryable);
}
}
catch (EntitySqlException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (EntityCommandExecutionException ex)
{
throw new ApplicationException("The object query failed", ex);
}
catch (SerializationException ex)
{
throw new ApplicationException("The object graph could not be serialized", ex);
}
}
|
|
|
|
|
What are you trying to do? You already have a persistent storage of the objects with all the foreign key lookups and so on: the database! Resolving references doesn't make sense without sending the entire data store, or at least a large part of it, at which point you might as well give the other client access to the data model directly.
The actual problem here, I think, is that the ObjectSet which is the type on the data context property is not serialisable. You may have to pull the tableA objects out into a List<tableA> and serialise that.
|
|
|
|
|
|
Dear all,
I have the C# windows form program which will export the Sales POS Receipts in PDF. But I find that due to fonts problem, the chinese and english words that make it not aligned for each line.
But I heard that there is a solution that will make the char length be the same for each letters in pixels by assigning full-width to chinese and half-width to english words.
Which library I can use for handling pixels length when exporting to PDF???
|
|
|
|
|
As far as I know the only way to do this is to use fixed width fonts such as Courier New, Terminal etc in English. I'm not sure whether there is a similar font for Chinese characters.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Hello every1, i'm doing some program on C#. I want to make so that some loop is running while button is pressed, if it is released loop ends. However on VS 2010 when i use Form1_MouseDown event inside loop is executed only once.
DL
|
|
|
|
|
Inside your MouseDown event:
1. Capture the mouse
2. Begin your repetitive operation
3. Handle the MouseUp event to stop the operation and release the mouse
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|